elasticsearch - decay documents using property value elasticsearch - decay documents using property value elasticsearch elasticsearch

elasticsearch - decay documents using property value


My query is/was correct. The issue was that my range 0.0 - 1.0 was to small. So I decided on using whole integers instead of decimals and range from 0 to 1000. For the exclusion I ten set the origin to 100 instead of 0. This returned the expected result.


Your understanding of the decay function parameters is correct. However, in your post you put the decay function (exp) clause inside the filter clause, which is wrong -- filters are only used to remove documents from the recall set, but cannot affect their score.

To use a decay function, you need to include it inside a function_score query. In your case you need something like:

{  "query": {    "function_score": {      "exp": {        "categoryDecayScore": {          "origin" : 0.0,          "scale" : 1.0,          "offset" : 0.0,          "decay" : 0.5        }      }    }  }}

If you only want this decay to affect documents having a categoryDecayScore > 0, you can add a filter to the decay function:

{  "query": {    "function_score": {      "exp": {        "filter": {          "range": {            "categoryDecayScore": {               "gt": 0.0             }          }        },        "categoryDecayScore": {          "origin" : 0.0,          "scale" : 1.0,          "offset" : 0.0,          "decay" : 0.5        }      }    }  }}

Also note that offset is 0 by default and decay is 0.5 by default, so you don't have to explicitly include those parameters.

The documentation for Decay Functions under the Function Score Query section has examples of the correct syntax and explanations about the defaults.