elasticsearch - 在 ES 查询过滤器上使用 match_phrase 两次?没有为 [match_phrase] 注册过滤器
问题描述
我一直在尝试使用多个过滤器获取文档。
我目前正在使用 ES 1.7 是否可以match_phrase
在过滤器上使用两次?
示例:人员文档
q=aaron&address=scarborough
- 按姓名和地址搜索人员,效果很好。
{
"query": {
"match_phrase": {
"name": "aaron"
}
},
"filter": {
"bool": {
"must": {
"nested": {
"path": "addresses",
"query": {
"match_phrase": {
"address": "scarborough"
}
}
}
}
}
},
q=aaron&phone=813-689-6889
- 通过姓名和电话号码搜索一个人也可以正常工作。
{
"query": {
"match_phrase": {
"name": "aaron"
}
},
"filter": {
"bool": {
"must": {
"query": {
"match_phrase": {
"phone": "813-689-6889"
}
}
}
}
}
但是,当我尝试同时使用过滤器、地址和电话时出现No filter registered for [match_phrase]
错误
例如:q=aaron&address=scarborough&phone=813-689-6889
{
"query": {
"match_phrase": {
"name": "aaron"
}
},
"filter": {
"bool": {
"must": {
"nested": {
"path": "addresses",
"query": {
"match_phrase": {
"address": "scarborough"
}
}
},
"query": {
"match_phrase": {
"phone": "813-689-6889"
}
}
}
}
}
一起使用address
和phone
过滤器时的错误:
nested: QueryParsingException[[pl_people] No filter registered for [match_phrase]]; }]","status":400}):
索引映射(人)按要求:
{
"pl_people": {
"mappings": {
"person": {
"properties": {
"ac_name": {
"type": "string",
"analyzer": "autocomplete"
},
"date_of_birth": {
"type": "date",
"format": "dateOptionalTime"
},
"email": {
"type": "string"
},
"first_name": {
"type": "string",
"fields": {
"na_first_name": {
"type": "string",
"index": "not_analyzed"
}
}
},
"last_name": {
"type": "string",
"fields": {
"na_last_name": {
"type": "string",
"index": "not_analyzed"
}
}
},
"middle_name": {
"type": "string",
"fields": {
"na_middle_name": {
"type": "string",
"index": "not_analyzed"
}
}
},
"name": {
"type": "string",
"fields": {
"na_name": {
"type": "string",
"index": "not_analyzed"
},
"ngram_name": {
"type": "string",
"analyzer": "my_start"
},
"ns_name": {
"type": "string",
"analyzer": "no_stopwords"
}
}
},
"phone": {
"type": "string"
},
"time": {
"type": "date",
"format": "dateOptionalTime"
},
"updated_at": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
}
}
解决方案
也许您可以使用 term-filter,而不是 match_phrase 作为过滤器。
见这里。
推荐阅读
- google-cloud-firestore - 多 Firestore 数据库
- php - 日期差异明天日期
- php - 选中另一个复选框时如何取消选中复选框?
- javascript - 如何在 nodejs (tensorflow.js) 中训练模型?
- angular - 如何从一组可观察对象中捕获所有不同的响应?
- delphi - 知道在 MS-Word 中到页面末尾还剩下多少行或空格
- android - 如何在图像上放置切换输入点?
- angular - NGXS dispatch-decorator 插件不能与 withLatestFromOperator 一起使用
- react-native - 框中出现奇怪的十字架代替 React-native-paper 的复选框
- unity3d - Unity:如何在游戏对象(文本或图像)周围创建一个类似于 Unity 编辑器中的选择框?