从ElasticSearch获取为什么结果很成功

时间:2019-04-18 22:12:08

标签: elasticsearch

在下面的ElasticSearch中,我在两个字段Balancesname中搜索单词notes

GET /_search

{ "query": {
    "multi_match": { "query": "Balances",
                     "fields": ["name","notes"] 
                   }
           }
 }

name字段中的结果:

   "hits" : {
     "total" : {
       "value" : 1,
       "relation" : "eq"
     },
     "max_score" : 1.673515,
     "hits" : [
       {
         "_index" : "idx",
         "_type" : "_doc",
         "_id" : "25",
         "_score" : 1.673515,
         "_source" : {
           "name" : "Deposits checking accounts balances",
           "notes" : "These are the notes",
           "@timestamp" : "2019-04-18T21:05:00.387Z",
           "id" : 25,
           "@version" : "1"
         }
       } 
      ]
    }

现在,我想知道ElasticSearch在哪个字段中找到了值。我可以评估结果,看看搜索到的文本是在name还是notes中,但是如果是模糊搜索,则无法做到这一点。

ElasticSearch能否告诉我在哪个字段中找到了文本,还可以在结果的左侧和右侧提供一个包含5个单词的代码段,以告诉用户为什么结果是匹配项?

我想要实现的功能类似于Google用粗体突出显示短语中找到的文本。

1 个答案:

答案 0 :(得分:1)

我认为Find out which fields matched in a multi match query中的2个解决方案仍然是有效的解决方案:

  • 突出显示它。
  • 将查询拆分为多个命名匹配查询。