Find the actual matching word when using fuzzy query in elastic search

I am new to elasticsearch and was looking for fuzzy queries search.
I made new index products with object / record values ​​like this

{
            "_index": "products",
            "_type": "product",
            "_id": "10",
            "_score": 1,
            "_source": {
                "value": [
                    "Ipad",
                    "Apple",
                    "Air",
                    "32 GB"
                ]
            }
        }

      

Now when I search for a fuzzy query in elasticsearch like

{
   query: {
       fuzzy: {
          value: "tpad"
       }
   }
}

      

It returns me the correct entry (the product just done above) that is expected.
And I know the term tpad

matches ipad

, so the entry was returned.
But technically, how would I know it fits ipad

. Elastic search just returns a complete record (or records) like this

{
"took": 4,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
},
"hits": {
    "total": 1,
    "max_score": 0.61489093,
    "hits": [
        {
            "_index": "products",
            "_type": "product",
            "_id": "10",
            "_score": 0.61489093,
            "_source": {
                "value": [
                    "Ipad",
                    "Apple",
                    "Air",
                    "32 GB"
                ]
            }
        }
    ]
}
}

      

Is there any way in elastic search so that I can know if it matches tpad

foripad

+3


source to share


3 answers


if you are using highlighting Elasticsearch will show the terms that match:

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

      



Elasticsearch will return matching documents with a selection:

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

      

+3


source


If you just want to analyze the result, you can use the Inquisitor plugin.

If you need to do this programmatically, I think the highlight function will help you:



Determining which words were matched in fuzzy search

+1


source


I know this is an older question, but I just ran into it. The way I do it is to fill in the query name field when building the query. Thus, it will return to the "matchedQuery" field in response. Hope this helps :)

+1


source







All Articles