# ES 6.2 Multiple Function Scores/Boost Modes

**URL:** <https://discuss.elastic.co/t/es-6-2-multiple-function-scores-boost-modes/127557>\
**Category:** Elasticsearch\
**Created:** [April 11, 2018, 12:59am UTC](https://discuss.elastic.co/t/es-6-2-multiple-function-scores-boost-modes/127557 "2018-04-11T00:59:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Hourany](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@Jon\_Hourany](https://discuss.elastic.co/u/Jon_Hourany)\
**Post date:** [April 11, 2018, 12:59am UTC](https://discuss.elastic.co/t/es-6-2-multiple-function-scores-boost-modes/127557/1 "2018-04-11T00:59:16Z")

</div>

I'm trying to add the Page Rank to the score of a document, adjusted by date decay. I know I can multiply the Rank and Date Decay together with a `"score_mode": "multiply"`, but I have other factors that I want summed, and I'm not sure how to break up the different ways I want portions scored and collected.

For example, lets say I'd like score to be:  
score = \_score + hierarchical\_weight + rank\*decay

I have only be able to figure out up this point  
score = \_score + hierarchical\_weight + rank + decay

As demonstrated with the following query

```
{
  "query": {
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "hierarchical_weight",
            "factor": 1,
            "modifier": "none",
          }
        },
        {
          "field_value_factor": {
            "field": "rank",
            "factor": 1,
            "modifier": "none",
          }
        },
        {
          "exp": {
            "date": {
              "origin": "now",
              "scale": "365d",
              "decay": 0.5
            }
          },
        }
      ],
      "score_mode": "sum",
      "boost_mode": "sum",
      "query": {
        "bool": {
          "should": [
            {
              "match": {[. . . truncated . . .]

```

Any help would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [April 11, 2018, 11:36am UTC](https://discuss.elastic.co/t/es-6-2-multiple-function-scores-boost-modes/127557/2 "2018-04-11T11:36:02Z")

</div>

You could nest a function score query inside of another function score query, where the inner function score query uses score\_mode `multiply` and the outer score\_mode `sum` (or in this case a boost\_mode `sum`). It's not pretty, and it may not be fast on larger datasets, but it works:

```auto
{
  "query": {
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "hierarchical_weight",
            "factor": 1,
            "modifier": "none"
          }
        }
      ],
      "score_mode": "sum",
      "boost_mode": "sum",
      "query": {
        "function_score": {
          "query": {
            "bool": {
              "should": [
                {
                  "match": {
                    "foo": "bar"
                  }
                }
              ]
            }
          },
          "functions": [
            {
              "field_value_factor": {
                "field": "rank",
                "factor": 1,
                "modifier": "none"
              }
            },
            {
              "exp": {
                "date": {
                  "origin": "now",
                  "scale": "365d",
                  "decay": 0.5
                }
              }
            }
          ],
          "score_mode": "multiply",
          "boost_mode": "sum"
        }
      }
    }
  }
}

```

Having said that, work is under way to make custom score calculation more flexible in Elasticsearch in the future. You can follow that work here: [https://github.com/elastic/elasticsearch/issues/23850](https://github.com/elastic/elasticsearch/issues/23850)

---

<div class="post-metadata">

**Author:** ![Jon\_Hourany](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@Jon\_Hourany](https://discuss.elastic.co/u/Jon_Hourany)\
**Post date:** [April 23, 2018, 7:57pm UTC](https://discuss.elastic.co/t/es-6-2-multiple-function-scores-boost-modes/127557/3 "2018-04-23T19:57:08Z")

</div>

Thank you for the reply, and the very informative link on the issue; it explains why it was so hard to find information on how to do this on my own.

---

<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:** [May 21, 2018, 7:57pm UTC](https://discuss.elastic.co/t/es-6-2-multiple-function-scores-boost-modes/127557/4 "2018-05-21T19:57:20Z")

</div>

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