Function_score for score_mode: sum returning 1 instead of 0

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:
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:
{
   "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.

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