mnd
mnd

Reputation: 2789

Boost a query word in Elasticsearch

Elasticsearch allows you to boost a field that you are searching on, but is it possible to "boost" the importance of a specific word in the query itself?

For example, I want to search for "Minnesota health care", and I want "Minnesota" to be more important than "health care" (because I don't want health care information from other states).

The closest thing I have found is using some type of custom_score query which allows you to change the scoring, and maybe I could use that to boost anything which actually includes the word that is more important. Not sure if that is possible.

Ideally I would be able to do this all programmatically, with a list of words that are considered "most important" for the application, and those could be found in incoming queries and "boosted".

Upvotes: 6

Views: 2890

Answers (1)

keety
keety

Reputation: 17441

There are probably multiple ways to achieve this one approach would be to use query_string where you can provide boost per individual terms

Example below shows a query where matches on Minnesota are boosted twice as much:

{ 
    "query" : {
        "query_string" : {
            "fields" : ["content", "name"],
            "query" : "Minnesota^2 health"
        }    
    }
}

Upvotes: 7

Related Questions