0

My question is about the boost function in elasticsearch (I've read their docs, and it's still quite unclear). Will the following "boost_mode" : "sum" apply to the boosts within the matches? Or since it's outside the enclosure perhaps it's just the sum of the final result, which is just the same as the default. I've got many fields and a vector of values - I want the scoring to be additive and not multiplicative. If the following does not work - any suggestions or pointers would be appreciated. Thanks!

"""
 |  "query": {
 |    "function_score": {
 |      "boost_mode": "sum",
 |      "query": {
 |        "bool": {
 |          "should": [
 |            { "match": { "someField":      { "query": "someValue",      "boost": 2 } } },
 |            { "match": { "someOtherField": { "query": "someOtherValue", "boost": 3 } } }
 |        }
 |      }
 |    }
 |  }
"""
1
  • I also realize that testing the query and looking at the scores will tell me something - and it does - the values are slightly different when I choose 'sum' vs. 'multiply' - but I also know that there is some calcs/normalization internally, and so this may not mean that I'm getting the desired results. Commented Aug 26, 2015 at 0:32

1 Answer 1

2

The way the sum boost mode works is that it computes the score according to the following formula:

queryBoost * (queryScore + Math.min(funcScore, maxBoost))

where:

  • queryBoost is the value of the boost parameter inside your function score, since there is none, it defaults to 1.0f
  • queryScore is the normal score of the query, in your case it's variable and depends on the searched terms and the additional boost you're setting in your match queries
  • funcScore is the result of the multiplication of the score of each of your filter functions, defaults to 1.0f
  • maxBoost is the value of the max_boost parameter inside your function score, since there is none, it defaults to Float.MAX_VALUE

Also worth noting is that since you have no filter functions, there is no funcScore to compute and the overall score is simply the queryScore. So based what precedes, the formula can be simplified to

queryScore

which means in the end that your overall score is directly related to your query score

A good thing is also to pass ?explain=true in your query so you can get more insights into how the score was computed. In your case, since you have no filter functions, the boost_mode is simply not used at all and the query score is returned instead.

If you were to add a functions parameter with one or more score functions, then the result would be different as a funcScore could be computed.

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

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.