# Boosting results using Function\_Score result unexpected behavior

**URL:** <https://discuss.elastic.co/t/boosting-results-using-function-score-result-unexpected-behavior/222820>\
**Category:** Elasticsearch\
**Created:** [March 9, 2020, 10:51pm UTC](https://discuss.elastic.co/t/boosting-results-using-function-score-result-unexpected-behavior/222820 "2020-03-09T22:51:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![auduwage](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@auduwage](https://discuss.elastic.co/u/auduwage)\
**Post date:** [March 9, 2020, 10:51pm UTC](https://discuss.elastic.co/t/boosting-results-using-function-score-result-unexpected-behavior/222820/1 "2020-03-09T22:51:34Z")

</div>

We have 3 stage ranking phase in our search engine. We use `BM25` with Distance Decay function and Freshness Decay function as the first phase. Then for the second stage, we use LTR plugin and do a rescoring with a `window_size`. Third stage we have another boosting mechanism implemented using `function_score`. Both LTR and and Boosting phase use the same `window_size`. Here is the implementation of the Boosting using `function_score`.

```
  {
    "window_size": {{rescore.window_size}},
    "query": {
      "rescore_query": {
        "function_score": {
          "boost_mode":"sum",
          "score_mode": "sum",
          "script_score" : {
            "script" : {
              {{#rescore.ym.params}}
              "params": {
                "min": {{rescore.ym.params.min}},
                "w_x": {{rescore.ym.params.w_x}},
                "w_y": {{rescore.ym.params.w_y}},
                "default_y": {{rescore.ym.params.default_y}},
              },
              {{/rescore.ym.params}}
              {{#rescore.ym.use_add_func}}
                  "source": "params.min + (doc['ValueA'].empty ? 0 : params.w_x * doc['ValueA'].value) + params.w_y * (doc['ValueB'].empty ? params.default_y : doc['ValueB'].value)"
              {{/rescore.ym.use_add_func}}
              {{^rescore.ym.use_add_func}}
              "source": "0"
              {{/rescore.ym.use_add_func}}
            }
          }
        }
      }
    }
  }

```

The math function in the `function_score` use two fields in the document and generate the `source` to be use during the ranking. I calculate the manually what the source should get during ranking time and looked at the results but it doesn't look like final ranking is preserving the boosting or have gotten enough boosting. Following image shows elastic document score and then manually calculated value. This show case that boosting didn't really take place (there a clusters) .

 ![Screen Shot 2020-03-09 at 11.26.50 AM](https://us1.discourse-cdn.com/elastic/original/3X/1/7/17812e4b10782e865f8ad22c153aa3a0b4d3f3ca.png)

Questions:

Is it due to baseline ranking? or is due to LTR and baseline contributing and the boosting done in function\_score is too small?

In addition to above I have tried multiply as boosting along with replace neither option generated rank order that reflect the score calculated in the function.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 6, 2020, 10:51pm UTC](https://discuss.elastic.co/t/boosting-results-using-function-score-result-unexpected-behavior/222820/2 "2020-04-06T22:51:35Z")

</div>

Closed on April 6, 2020, 10:51pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
