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".
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.
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?
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.
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.
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"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With