2

I have a question in using the field_value_factor with ElasticSearch.

The function that I would like to implement is

alpha * log(1 + beta * doc['popularity'].value)

When alpha = 1.0, the script using the field_value_factor is given by

"field_value_factor": {
  "field": "popularity",
  "factor": beta,
  "modifier": "log1p"
}

as shown in this link:

However, when alpha != 1.0, how we can give the weight (i.e. alpha) using the field_value_factor?

Do you have any idea for this?

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
Seung-Hoon Na
  • 21
  • 1
  • 2

1 Answers1

3

Function score can be cascaded so a combination of boost_factor and field_value_factor should allow you to achieve the same.

{
   "query": {
      "function_score": {
         "query": {
            "match_all": {}
         },
         "functions": [
            {
               "boost_factor": <alpha>
            },
            {
               "field_value_factor": {
                  "field": "popularity",
                  "factor": <beta>,
                  "modifier": "log1p"
               }
            }
         ],
         "score_mode": "multiply"
      }
   }
}
keety
  • 17,231
  • 4
  • 51
  • 56