Favor exact matches over nGram in elasticsearch Favor exact matches over nGram in elasticsearch elasticsearch elasticsearch

Favor exact matches over nGram in elasticsearch


Understating how score is calculated

Elasticsearch has an option for producing an explanation with every search result. by setting the explain parameter to be true

POST  <Index>/<Type>/_search?explain&format=yaml{"query" : " ....."}

it will produce a lot of output for every hit and that can be overwhelming, but it worth taking some time to understand what it all means

the output of eplian might be harder to read in json, so adding format=yaml makes it easier to read

Understanding why a document is matched or not

you can pass the query to a specific document like below to see explanation how matching is being done.

GET <Index>/<type>/<id>/_explain{"query": "....."}


The multi_field mapping is correct, but the search query needs to be changed like this:

{    "query": {        "filtered": {            "query": {                "multi_match": { # changed from "query_string"                    "fields": ["name","name.exact"],                    "query": "Woods",                    # added this so the engine does a "sum of" instead of a "max of"                    # this is deprecated in the latest versions but works with 0.x                    "use_dis_max": false                }            }        }    }}

Now the results take into account the 'exact' match and adds up to the score.