我是 Elasticsearch 的新手,我们正在研究一个需求,弹性搜索中的文档将根据模糊匹配、Wordmatch等匹配类型来获取......
我们在这里面临性能问题,当文档与一种匹配类型匹配时,文档应该来自“bool”查询,但它参与了所有匹配类型并给了我所有匹配类型的结果,我尝试嵌套bool 查询使其参与单个匹配类型并在匹配时退出,否则移动到下一个匹配类型。
我试着关注这个博客。
[ https://www.elastic.co/blog/lost-in-translation-boolean-operations-and-filters-in-the-bool-query][1]
即使这给我带来了同样的结果..
请找到以下示例代码。
{
"size": 10000,
"query": {
"function_score": {
"score_mode": "sum",
"functions": [
{
"filter": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"4": {
"fuzziness": "AUTO",
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.fuzzyMatch"
}
}
},
{
"match": {
"4": {
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.wordMatch"
}
}
}
]
}
},
{
"bool": {
"should": [
{
"match": {
"4.subStringMatch": {
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.subStringMatch"
}
}
},
{
"match": {
"4.phoneticMatch": {
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.phoneticMatch"
}
}
}
]
}
},
{
"match": {
"4.exactMatch": "kavan"
}
}
]
}
},
"weight": 50
}
]
}
}
}
实际输出为:
"hits": {
"total": 94,
"max_score": 50.0,
"hits": [{
"_index": "6_1028",
"_type": "6_1028",
"_id": "14",
"_score": 50.0,
"_source": {
"1": 14,
"@timestamp": "2018-05-18T06:57:02.540Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch", "4.fuzzyMatch", "4.subStringMatch"]
}, {
"_index": "6_1028",
"_type": "6_1028",
"_id": "52",
"_score": 50.0,
"_source": {
"1": 52,
"@timestamp": "2018-05-18T06:57:02.559Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch", "4.fuzzyMatch", "4.subStringMatch"]
}, {
"_index": "6_1028",
"_type": "6_1028",
"_id": "53",
"_score": 50.0,
"_source": {
"1": 53,
"@timestamp": "2018-05-18T06:57:02.559Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch", "4.fuzzyMatch", "4.subStringMatch"]
}
}
预期输出为:
"hits": {
"total": 94,
"max_score": 50.0,
"hits": [{
"_index": "6_1028",
"_type": "6_1028",
"_id": "14",
"_score": 50.0,
"_source": {
"1": 14,
"@timestamp": "2018-05-18T06:57:02.540Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch"]
}
在matched_queries中只有一种匹配类型
注意:匹配类型可以在matched_queries块中看到。
在这方面的任何建议表示赞赏..