我使用bool
查询查询弹性搜索索引。查询本身具有与此
{
"query": {
"bool": {
"should": [
{"multi_match": {
"fields": ["field1", "field2"],
"query": self.cleaned_stemmed_phrase,
"type": "phrase",
"fuzziness":"AUTO"
}},
{"multi_match": {
"fields": ["field3"],
"query": self.cleaned_stemmed_phrase,
"fuzziness":"AUTO",
"boost": 4
}},
{"multi_match": {
"fields": ["field4"],
"query": self.cleaned_stemmed_phrase,
"fuzziness":"AUTO"
}},
{"multi_match": {
"fields": ["field5", "filed6"],
"query": self.spaces_removed,
"fuzziness":"AUTO"
}},
{"multi_match": {
"fields": ["field7", "field8"],
"query": self.no_space_stems,
"fuzziness":"AUTO"
}}
]
}
}
}
我希望能够确定所有这些查询中的哪一个是匹配结果的一个(一个)。是否有内置的弹性搜索方法允许或者我必须手动执行此操作?
答案 0 :(得分:2)
您可以使用named queries,然后在结果中获取匹配的查询的名称。
{
"query": {
"bool": {
"should": [
{"multi_match": {
"fields": ["field1", "field2"],
"query": self.cleaned_stemmed_phrase,
"type": "phrase",
"fuzziness":"AUTO",
add name ---> "_name": "query1"
}},
{"multi_match": {
"fields": ["field3"],
"query": self.cleaned_stemmed_phrase,
"fuzziness":"AUTO",
"boost": 4,
add name ---> "_name": "query2"
}},
{"multi_match": {
"fields": ["field4"],
"query": self.cleaned_stemmed_phrase,
"fuzziness":"AUTO",
add name ---> "_name": "query3"
}},
{"multi_match": {
"fields": ["field5", "filed6"],
"query": self.spaces_removed,
"fuzziness":"AUTO",
add name ---> "_name": "query4"
}},
{"multi_match": {
"fields": ["field7", "field8"],
"query": self.no_space_stems,
"fuzziness":"AUTO",
add name ---> "_name": "query5"
}}
]
}
}
}
然后在结果中,您将获得一个matched_queries
数组,其中包含与文档匹配的查询名称。
"_source": {
...
},
"matched_queries": [
"title_query"
],