我在Elasticsearch中查询了multi_match:
{
"query": {
"multi_match": {
"query": "luk",
"fields": [
"xml_string.autocomplete",
"state"
]
}
},
"size": 10,
"fields": [
"xml_string",
"state"
]
}
效果很好,结果返回预期值:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.41179964,
"hits": [
{
"_index": "documents",
"_type": "document",
"_id": "11",
"_score": 0.41179964,
"fields": {
"xml_string": "Lukas bla bla bla",
"state": "new"
}
}
]
}
}
我搜索了很多,但是我无法找出哪个字段与查询匹配(如果它是xml_string OR状态)
答案 0 :(得分:9)
我找到了解决方案:我使用了突出显示功能,而且效果很好
这就是我的卷发的样子:
curl -X GET 'http://xxxxx.com:9200/documents/document/_search?load=false&size=10&pretty' -d '{
"query": {
"multi_match": {
"query": "123",
"fields": ["some_field", "another_field"]
}
},
"highlight": {
"fields": {
"some_field": {},
"another_field": {}
}
},
"size": 10,
"fields": ["field","another_field"]
}'
答案 1 :(得分:0)
据我所知,没有任何功能可以告诉您哪个字段与查询匹配。
但您可以使用说明功能来调试查询。您只需在查询中添加pamameter &explain=true
即可。使用此参数,您将看到每个字段对结果集中原因的解释,您将猜测哪个字段与查询匹配。