Alkis Kalogeris
Alkis Kalogeris

Reputation: 17735

Elasticsearch decay function score

I'm trying the below

PUT test/foo/1
{
  "num": 100
}

GET test/foo/_search
{
  "query" : {
    "function_score" : {
      "query" : {
        "match" : {
          "num": 100
        }
      },
      "functions" : [
        {
          "filter" : {
            "match_all" : {
            }
          },
          "gauss" : {
            "num" : {
              "origin": 0,
              "scale" : 500,
              "offset" : 0,
              "decay" : 0.1
            },
            "multi_value_mode" : "MIN"
          }
        }
      ],
      "score_mode" : "sum",
      "max_boost" : 3.4028235E38
    }
  }
}

---

{  
  "hits": {
    "total": 1,
    "max_score": 0.91201085,
    "hits": [
      {
        "_index": "test",
        "_type": "foo",
        "_id": "1",
        "_score": 0.91201085,
        "_source": {
          "num": 100
        }
      }
    ]
  }
}

I'm using sum as score mode. Since the score of the query is 1 and the score of the decay function is 0.91201085 I was expecting the score to be 1.91201085. What am I missing?

Upvotes: 0

Views: 1218

Answers (1)

user3775217
user3775217

Reputation: 4803

use "boot_mode" : "sum" . You can also use explain in query to understand how the document was scored

POST testindexy/_search
{
  "query" : {
    "function_score" : {
      "query" : {
        "match" : {
          "num": 100
        }
      },
      "functions" : [
        {
          "filter" : {
            "match_all" : {
            }
          },
          "gauss" : {
            "num" : {
              "origin": 0,
              "scale" : 500,
              "offset" : 0,
              "decay" : 0.1
            },
            "multi_value_mode" : "MIN"
          }
        }
      ],
      "boost_mode": "sum", 
      "score_mode" : "sum",
      "max_boost" : 3.4028235E38
    }
  }
}

Upvotes: 1

Related Questions