Field_value_factor use max of score

I have the following query:

{
  "query": {
    "function_score": {
      "boost_mode": "multiply",
      "functions": [
        {
          "field_value_factor": {
            "factor": 0.5,
            "field": "albums.trending_status_monthly",
            "missing": 2,
            "modifier": "sqrt"
          }
        }
      ],
      "query": {
       // ....
      }
    }
  },
  "sort": [
    "_score"
  ]
}

album is an array of albums with individual trending scores. When I run an explain for this query, I see that Elasticsearch uses the min of albums.trending_status_monthly:

{
              "value" : 2.345208,
              "description" : "min of:",
              "details" : [
                {
                  "value" : 2.345208,
                  "description" : "field value function: sqrt(doc['albums.trending_status_monthly'].value?:2.0 * factor=0.5)",
                  "details" : [ ]
                },
                {
                  "value" : 3.4028235E38,
                  "description" : "maxBoost",
                  "details" : [ ]
                }
              ]
            }

How can I change this to use the max score? Im trying to prevent using scripts as this is going to slow down the query.

Hi @Alexander_Engel

Are you talking about the maxBoost value?

HI @RabBit_BR

sorry, I wasn't clear about that. Lets assume there is a album with trending score 120, and one album with trending score 0. Per the explain statement above (line 3) the min of both calculated scores is used. Im trying to use the max.

Edit: I just noticed to min of is referring to maxBoost vs field value function. How can I use the max trending value? Something like "field": "max(albums.trending_status_monthly)"

I did a bit of research and didn't really find anything that could help you.

A suggestion is to have a new field that represents the highest trending_status_monthly of the album array. You can do this at the time of indexing and that way you will succeed when using the field_value_factor.

Let's see if someone on Team Elastic has a technical answer to this behavior.

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