# Function\_score for score\_mode: sum returning 1 instead of 0

**URL:** <https://discuss.elastic.co/t/function-score-for-score-mode-sum-returning-1-instead-of-0/287679>\
**Category:** Elasticsearch\
**Created:** [October 26, 2021, 10:38am UTC](https://discuss.elastic.co/t/function-score-for-score-mode-sum-returning-1-instead-of-0/287679 "2021-10-26T10:38:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hexer338](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hexer338/32/47413_2.png) [@hexer338](https://discuss.elastic.co/u/hexer338)\
**Post date:** [October 26, 2021, 10:38am UTC](https://discuss.elastic.co/t/function-score-for-score-mode-sum-returning-1-instead-of-0/287679/1 "2021-10-26T10:38:30Z")

</div>

Hi,

When using function\_score query with score\_mode: "sum", calculated score is returned as 1 instead of 0.

Elasticsearch Version: 7.1.0

**Steps to Reproduce:**

1. Index a document and search using function\_score query:

```auto
PUT test_index1
PUT test_index1/_doc/1
{
    "name": "John"
}

GET test_index1/_search
{
   "explain": true,
   "query": {
      "function_score": {
         "query": {
            "match_all": {}
         },
         "boost_mode": "replace",
         "score_mode": "sum",
         "functions": [
            {
               "weight": 0,
               "filter": {
                  "match": {
                     "name": "John"
                  }
               }
            }
         ]
      }
   }
}

```

1. We get following response from Elasticsearch:

```auto
{
   "took": 5,
   "timed_out": false,
   "_shards": {
      "total": 1,
      "successful": 1,
      "skipped": 0,
      "failed": 0
   },
   "hits": {
      "total": {
         "value": 1,
         "relation": "eq"
      },
      "max_score": 1,
      "hits": [
         {
            "_shard": "[test_index1][0]",
            "_node": "-PuGLG0WS5m6JgQrwTiR9A",
            "_index": "test_index1",
            "_type": "_doc",
            "_id": "1",
            "_score": 1,
            "_source": {
               "name": "John Doe"
            },
            "_explanation": {
               "value": 1,
               "description": "min of:",
               "details": [
                  {
                     "value": 1,
                     "description": "function score, score mode [sum]",
                     "details": [
                        {
                           "value": 0,
                           "description": "function score, product of:",
                           "details": [
                              {
                                 "value": 1,
                                 "description": "match filter: name:john name:doe",
                                 "details": []
                              },
                              {
                                 "value": 0,
                                 "description": "product of:",
                                 "details": [
                                    {
                                       "value": 1,
                                       "description": "constant score 1.0 - no function provided",
                                       "details": []
                                    },
                                    {
                                       "value": 0,
                                       "description": "weight",
                                       "details": []
                                    }
                                 ]
                              }
                           ]
                        }
                     ]
                  },
                  {
                     "value": 3.4028235e+38,
                     "description": "maxBoost",
                     "details": []
                  }
               ]
            }
         }
      ]
   }
}

```

As you can see from explanation, for `score mode [sum]`, the value is set to 1 when value is 0.

---

<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:** [November 23, 2021, 10:39am UTC](https://discuss.elastic.co/t/function-score-for-score-mode-sum-returning-1-instead-of-0/287679/2 "2021-11-23T10:39:00Z")

</div>

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