【问题标题】:Which field matched query in multi_match search in Elasticsearch?Elasticsearch中multi_match搜索中哪个字段匹配查询?
【发布时间】:2016-12-09 19:50:00
【问题描述】:

我在 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 state)

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我找到了解决方案:我使用了高亮功能,效果很好

    这就是我的卷曲的样子:

     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"]
    }'
    

    【讨论】:

    • 完美我的朋友...它在匹配字段需要处理时使用。
    【解决方案2】:

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

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

    【讨论】:

    • 感谢您的回复。我担心有人会写这种答案:) 我正在寻找某种方法来搜索多个字段,并知道哪个字段返回值。它用于自动完成。在以后的版本中,它应该返回发票号码,或者供应商名称......
    • 我找到了解决方案,我已将其添加为新答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    相关资源
    最近更新 更多