27

I am new to elasticsearch. In elasticsearch we can use the term boost in almost all queries. I understand it's used for modify score of documents. But i can't find actual use of it. My query is if i use boost values in some queries, will it affect final score of search or the boost rank of docs in index itself.

And what is main difference between boost at index and boost at querying..

Thanks in Advance..!

0

3 Answers 3

39

Query time boost allows you to give more weight to one query than to another. For instance, let's say you are querying the title and body fields for "Quick Brown Fox", you could write it as:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": "Quick Brown Fox"
          }
        },
        {
          "match": {
            "body": "Quick Brown Fox"
          }
        }
      ]
    }
  }
}

But you decide that you want the title field to be more important than the body field, which means you need to boost the query on the title field by (eg) 2:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": {
              "query": "Quick Brown Fox",
              "boost": 2
            }
          }
        },
        {
          "match": {
            "body": "Quick Brown Fox"
          }
        }
      ]
    }
  }
}

(Note how the structure of the match clause changed to accommodate the boost parameter).

The boost value of 2 doesn't double the _score exactly - the scores go through a normalization process. So you should think of boost as make this query clause relatively more important than the other query clauses.

My doubt is if i use boost values in some queries. will it affect final score of search

Yes it does, but you shouldn't rely on the actual value of _score anyway. Its only purpose is to allow Elasticsearch to decide which documents are most relevant to this query. If the query changes, the scores change.

Re index time boosting: don't use it. It's inflexible and error prone.

Sign up to request clarification or add additional context in comments.

1 Comment

So the boost does what exactly? All boosts are multiplicatively normalised so they sum to 1, and then used as multipliers? So boosts of 2 and 1 become score multipliers of 2/3 and 1/3?
5

Boost at query time won't modify your index. It only applies boost factor on fields when searching.

I prefer boost at query time as it's more flexible. If you need to change your boost rules and you had set it at index time, you will probably need to reindex.

1 Comment

could you please tell me any real time use of boost??? still i cant find full usage of it..!
2

Use cases of boosting : Suppose you are building a e-commerce web app, and your product data is in elastic search. Whenever a customer uses search bar you query elastic search and displays the result in web app. Elastic search keeps relevance score for every document and returns the result in sorted order of the relevance score. Now let's assume a user searches for "samsung phones", then should your web app just show samsung phones -> Answer is NO. Your web app should show other phones as well (as user may like those as well) but first show samsung phones (as he/she is looking for those) and then show other phones as well.

So question is how do you query where samsung phones comes up in result ? -> Answer is relevance score. Let say you hit query like for all mobile phones and samsung phone and the keep high relevance score of samsung phones, Then result will contain first samsung phones and then other phones.

Comments

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.