elasticsearch - 如何找到与不同查询中的所有单词匹配的文档?
问题描述
例如,使用此映射:
PUT /unit-test
{
"mappings": {
"properties": {
"name": { "type": "text" },
"landlords": {
"type": "nested",
"properties": {
"name": { "type": "text" }
}
}
}
}
}
如果我有这个文件:
{
"name": "T2 - Boulevard Haussmann - P429",
"landlords": [
{ "name": "John Doe" }
]
}
我希望“boulevard hausmann”和“boulevard haussman doe”匹配,但不匹配“rue haussman”或“haussman jeanne”。
我不能使用multi_match
with"operator": "and"
因为landlords
是嵌套的。
解决方案
一个想法是将copy_to映射参数设置为name
andlandlords.name
字段,以便将两个字段的值复制到names
您将用于搜索的另一个字段(例如 )中。
因此,您的映射可能如下所示:
{
"mappings": {
"properties": {
"name": {
"type": "text",
"copy_to": "names"
},
"landlords": {
"type": "nested",
"properties": {
"name": {
"type": "text",
"copy_to": "names"
}
}
},
"names": {
"type": "text"
}
}
}
}
和你的搜索
{
"query": {
"match": {
"names": {
"query": "boulevard haussman doe",
"operator": "AND"
}
}
}
}
推荐阅读
- php - 如何检查我的ipn页面是否被coinbase ping webhook通知调用
- powershell - 移动桌面项目
- swift - 如何在具有自己的登录/注册系统的应用上实现非消耗性应用内购买?
- python - 在 Python 中从 XML 中提取数据
- angular - 选择器“app-root”不匹配任何元素|| 角度 6
- python - 在 Heroku 中更新 bson 后,Flask 应用程序损坏
- excel - 尝试激活已打开的工作簿时下标超出范围
- sensenet - 如何在 sensenet 社区版中添加文档查看器
- javascript - 为什么getter不返回值
- android - 如何在我们自己的应用程序中添加 zomato 评级选项?