Range query with fuzzification

Hi,

Suppose you are looking for a candidates aged between 30 and 35, a very good qualified 36 year old candidate is valid as well, certainly when few candidates are found between 30 and 35.

How can I add fuzziness to range query? Also it would be better if 36 year old has smaller score on the age condition.

I'm expecting a query which results candidates in between 30 and 35 also includes 25(30-5) to 40(35+5)

"range" : {
"age" : {
"gt" : 30,
"lt" : 35,
"fuzziness" : 5
}
}

You could use a function_score query with

  1. A query that limits candidates of age between 25 and 40 with a range query (these are the hard bound limits)
  2. A decay function on age with an origin of 32.5 and offset of 2.5, and a scale, decay and decay function (gaussian, linear, etc) of your choosing. The origin and offset will ensure 30-35 are scored equally with a decay in score after those bounds.

Hi Russ,

Thanks for the solution. I am going for the second option to control the weight of decay function. That's fine for me to have same score(75% of 15) after original bounds.

"function_score": {
  "query": {....},
  "functions": [
    {
      "weight": 15,
      "gauss": {
        "age": {
          "origin": 32.5,
          "scale": 5,
          "offset": 2.5,
          "decay": 0.75
        }
      }
    }
  ]
}

No worries, happy to help :slight_smile: origin of 30 and offset of 5 will equally score 25-35 and gaussian decay after that.

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