Find actual matching word when using fuzzy query in elastic search

爷,独闯天下 提交于 2019-12-05 10:00:55

if you use highlighting, Elasticsearch will show the terms that matched:

curl -XGET http://localhost:9200/products/product/_search?pretty -d '{
  "query" : {
    "fuzzy" : {
        "value" : "tpad"
      }
  },
  "highlight": {
    "fields" : {
        "value" : {}
    }
  }
}'

Elasticsearch will return matching documents with the fragment highlighted:

{
  "took" : 31,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.13424811,
    "hits" : [ {
      "_index" : "products",
      "_type" : "product",
      "_id" : "10",
      "_score" : 0.13424811,
      "_source":{
 "value" : ["Ipad",
                "Apple",
                "Air",
                "32 GB"
                ]
           },
      "highlight" : {
        "value" : [ "<em>Ipad</em>" ]
      }
    } ]
  }
}
Luiz Henrique Zambom Santana

if you just want to analyze the result, you could use the Inquisitor plugin.

If you need to do this programmatically, I think the highlighting feature will help you:

Determining which words were matched in a fuzzy search

I know the question is older but I just ran into it. The way I do it is by populating the query name field when building the query. This way it will come back inside the "matchedQuery" field in response. Hope this helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!