Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch boost importance of exact phrase match

Tags:

Is there a way in elasticsearch to boost the importance of the exact phrase appearing in the the document?

For example if I was searching for the phrase "web developer" and if the words "web developer" appeared together they would be boosted by 5 compared to "web" and "developer" appearing separately throughout the document. Thereby any document that contained "web developer" together would appear first in the results.

like image 380
user2724314 Avatar asked Aug 28 '13 07:08

user2724314


1 Answers

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     }   } } 
like image 105
javanna Avatar answered Oct 07 '22 21:10

javanna