Elasticsearch中multi_match搜索中哪个字段匹配查询?

ger*_*uda 9 elasticsearch

我在Elasticsearch中使用multi_match进行查询:

{
  "query": {
    "multi_match": {
      "query": "luk",
      "fields": [
        "xml_string.autocomplete",
        "state"
      ]
    }
  },
  "size": 10,
  "fields": [
    "xml_string",
    "state"
  ]
}
Run Code Online (Sandbox Code Playgroud)

效果很好,结果返回预期值:

{
  "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"
        }
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我搜索了很多,但我无法找出哪个字段与查询匹配(如果它是xml_string OR状态)

ger*_*uda 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"]
}'
Run Code Online (Sandbox Code Playgroud)


mol*_*are 0

据我所知,没有任何功能可以告诉您哪个字段与查询匹配。

但您可以使用解释功能来调试查询。您只需将 pamameter 添加到查询中&explain=true。使用此参数,您将看到每个字段的解释,说明为什么它出现在结果集中,并且您将猜测哪个字段与查询匹配。