7

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

2
  • it means you want documents that match Minnesota but not necessarily health care ? Commented May 27, 2015 at 18:38
  • 1
    It means that documents with "Minnesota" and "health care" should show up, but that any other "Minnesota" documents would show up before other "health care" documents. For instance, "Minnesota car care" would show up before "Iowa health care". Hopefully that will clarify. Commented May 27, 2015 at 19:13

1 Answer 1

8

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"
        }    
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

One follow up question, do you know if this is possible with the multi_match query? I'm interested because multi_match will support partial results in different fields. Given your example above, "Minnesota" could be in the "content" field and "health" could be in the "name" field. Thanks.
@mnd there is no option in multi-match for this but query string allows for partial results in different fields just like the example in the answer elastic.co/guide/en/elasticsearch/reference/current/…
you're right, I had bad data which made me think it wasn't searching other fields. Your answers have been terrific, thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.