# Score\_mode avg returns 1 for all documents

**URL:** <https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822>\
**Category:** Elasticsearch\
**Created:** [February 11, 2020, 4:33pm UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822 "2020-02-11T16:33:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [February 11, 2020, 4:33pm UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/1 "2020-02-11T16:33:20Z")

</div>

Hi Elasticians!

I'm using function score with score\_mode avg and boost\_mode replace.  
And according to documentation I'm expecting the query function score to be overriden by the function score filters.

This works as expected for the sum and multiply, but not for avg (I'm aware that the average in function score is a weighted average)

When I apply this function\_score all the documents get a score of 1.  
How can this happen?

```
GET kibana_sample_data_ecommerce/_search
{
  "_source": {
    "includes": ["customer_last_name", "customer_first_name", "customer_gender"]
    
  }, 
  "size": 10, 
  "query": {
    "function_score": {
      "functions": [
        {
          "filter": { "match": { "customer_last_name": "Cook" } },
          "weight": 2
        },
        {
          "filter": { "match": { "customer_first_name": "Jackson" } },
          "weight": 2
        },
        {
          "filter": { "match": { "customer_gender" : "MALE"} },
          "weight": 2
        }
      ],
      "score_mode": "multiply", 
      "boost_mode": "replace"
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [February 14, 2020, 8:07am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/2 "2020-02-14T08:07:20Z")

</div>

UPDATED CODE SAMPLE (With avg instead of multiply)

```
GET kibana_sample_data_ecommerce/_search
{
  "_source": {
    "includes": ["customer_last_name", "customer_first_name", "customer_gender"]
    
  }, 
  "size": 10, 
  "query": {
    "function_score": {
      "functions": [
        {
          "filter": { "match": { "customer_last_name": "Cook" } },
          "weight": 2
        },
        {
          "filter": { "match": { "customer_first_name": "Jackson" } },
          "weight": 2
        },
        {
          "filter": { "match": { "customer_gender" : "MALE"} },
          "weight": 2
        }
      ],
      "score_mode": "avg", 
      "boost_mode": "replace"
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [February 20, 2020, 2:08pm UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/3 "2020-02-20T14:08:09Z")

</div>

Anyone can help with this one?

Thanks

---

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [February 28, 2020, 7:52am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/4 "2020-02-28T07:52:35Z")

</div>

Hi there can someone help with this one?

---

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [March 9, 2020, 7:30am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/5 "2020-03-09T07:30:23Z")

</div>

Is there someone who understands about scoring who can help?

Thanks

---

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [March 9, 2020, 7:37am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/6 "2020-03-09T07:37:08Z")

</div>

I have initiated a 50 points bounty in stackoverflow for this same question

> <https://stackoverflow.com/questions/60191153/score-mode-avg-returns-1-for-all-documents>

---

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [March 9, 2020, 10:21am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/7 "2020-03-09T10:21:12Z")

</div>

In my question, even if the functions weights are diferent I Still get 1 as score

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 9, 2020, 10:55am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/8 "2020-03-09T10:55:46Z")

</div>

@jimczi do you know?

---

<div class="post-metadata">

**Author:** ![wall](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@wall](https://discuss.elastic.co/u/wall)\
**Post date:** [March 19, 2020, 6:32am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/9 "2020-03-19T06:32:50Z")

</div>

Hi @dadoonet Thank you for the try here for helping me out!

I think I figured it out. the whys I don't know exactly.

But when one of the filters don't match it is doesn't seem to be took into acount in the formula weighted average formula.

More over is that if no filter is matched the score is defined between the min value of 1, and a very large value.

As a result, all if an element match 2 filters it will get 1, because the other 1 filter does not enter in the formula, an element with 1 match filter gets 1 score because the other 2 unmatched filters are also not took into acount. and the 100% unmatched filter documents, get 1 because it is the min between 1, and a very large number. So it really looks like no matter the case we will get always 1 score, when we use score\_mode avg and boost\_mode replace. I don't know if it happens for boost\_mode too but it's out of the scope of this question.

I obtain this information by exploring explain API.

Have a great day, and take care about the corona virus!

---

<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 16, 2020, 6:32am UTC](https://discuss.elastic.co/t/score-mode-avg-returns-1-for-all-documents/218822/10 "2020-04-16T06:32:50Z")

</div>

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