Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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".

like image 621
mnd Avatar asked May 27 '15 18:05

mnd


People also ask

How do I boost terms and query clauses when searching in Elasticsearch?

This article explains how to boost terms and query clauses when searching in Elasticsearch. When searching for multiple terms, it is sometimes useful to be able to assign a higher or lower priority to certain terms. Elasticsearch provides a way of doing this by specifying a positive floating point number. Below is an example query.

How do I reduce the relevance score in Elasticsearch?

Take the original relevance score from the positive query. Multiply the score by the negative_boost value. (Required, float) Floating point number between 0 and 1.0 used to decrease the relevance scores of documents matching the negative query. What is Elasticsearch?

How do I boost the term Spaghetti in a Elasticsearch query?

Elasticsearch provides a way of doing this by specifying a positive floating point number. Below is an example query. As you can see in this query, I am boosting the term spaghetti by using the boost operator followed by a floating point number.

How does Elasticsearch work with search query?

For information about running a search query in Elasticsearch, see Search your data. Returns documents based on a provided query string, using a parser with a strict syntax. This query uses a syntax to parse and split the provided query string based on operators, such as AND or NOT.


1 Answers

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"
        }    
    }
}
like image 61
keety Avatar answered Sep 23 '22 16:09

keety