Search code examples
elasticsearchquerydslelasticsearch-dsl

What does this elasticsearch query mean?


I want to find best movie/webseries from past 6 months to now and it should have good rating also.

POST sample-movie-2022.02.08/_search
{
  "query": {
    "function_score": {
      "functions": [
        {
          "gauss": {
            "rating": {
              "origin": "10",
              "scale": "1"
            }
          }
        },
        {
          "gauss": {
            "release_date": {
              "origin": "now",
              "scale": "180d"
            }
          }
        }
      ]
    }
  }
}

The query gives different score when i change rating scale like 1,7,8.I actually don't know what does it mean in rating but i understood origin and scaling in relase_date


Solution

  • You're using a decay functions (i.e. gauss) and the parameters to that function mean:

    • origin: the point of origin from where the "distance" is computed
    • offset (default 0 as in your case): means that the decay starts right at the origin (i.e. origin ± offset = origin in your case)
    • scale: the point at which the function will take the value of decay (i.e. origin ± offset ± scale)
    • decay (default 0.5 as in your case): the score at the scale point (i.e. the score at origin ± offset ± scale

    So, concretely in your case what it means is that:

    • documents with a rating of 10 will score 1
    • documents with a rating of 9 or 11 (scale = 10 ± 1) will score 0.5
    • documents with a rating <9 or >11 will score below 0.5

    So the offset and scale parameters allow you to define the inflection point from which the scoring will decay.

    enter image description here