elasticsearch boost importance of exact phrase match elasticsearch boost importance of exact phrase match elasticsearch elasticsearch

elasticsearch boost importance of exact phrase match


You can combine different queries together using a bool query, and you can assing a different boost to them as well. Let's say you have a regular match query for both the terms, regardless of their positions, and then a phrase query with a higher boost.

Something like the following:

{  "query": {    "bool": {      "should": [        {          "match": {            "field": "web developer"          }        },        {          "match_phrase": {            "field": "web developer",            "boost": 5          }        }      ],      "minimum_number_should_match": 1    }  }}


As an alternative to javanna's answer, you could do something similar with must and should clauses within a bool query:

{  "query": {    "bool": {      "must": {          "match": {            "field": "web developer",            "operator": "and"          }      },      "should": {          "match_phrase": {            "field": "web developer"          }      }    }  }}

Untested, but I believe the must clause here will match results containing both 'web' and 'developer' and the should clause will score phrases matching 'web developer' higher.


You could try using rescore to run an exact phrase match on your initial results. From the docs:

"Rescoring can help to improve precision by reordering just the top (eg 100 - 500) documents returned by the query and post_filter phases, using a secondary (usually more costly) algorithm, instead of applying the costly algorithm to all documents in the index."

https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-search-results.html#rescore