# Field\_value\_factor use max of score

**URL:** https://discuss.elastic.co/t/field-value-factor-use-max-of-score/327971
**Category:** Elasticsearch
**Created:** [March 17, 2023, 8:11pm UTC](https://discuss.elastic.co/t/field-value-factor-use-max-of-score/327971 "2023-03-17T20:11:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Alexander\_Engel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_engel/32/118585_2.png) [@Alexander\_Engel](https://discuss.elastic.co/u/Alexander_Engel)
#### Post date: [March 17, 2023, 8:11pm UTC](https://discuss.elastic.co/t/field-value-factor-use-max-of-score/327971/1 "2023-03-17T20:11:41Z")

</div>

I have the following query:

```auto
{
  "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`:

```auto
{
              "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.

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [March 17, 2023, 8:49pm UTC](https://discuss.elastic.co/t/field-value-factor-use-max-of-score/327971/2 "2023-03-17T20:49:49Z")

</div>

Hi @Alexander_Engel

Are you talking about the maxBoost value?

---

<div class="post-metadata">

### Author: ![Alexander\_Engel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_engel/32/118585_2.png) [@Alexander\_Engel](https://discuss.elastic.co/u/Alexander_Engel)
#### Post date: [March 17, 2023, 9:16pm UTC](https://discuss.elastic.co/t/field-value-factor-use-max-of-score/327971/3 "2023-03-17T21:16:18Z")

</div>

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)"`

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [March 18, 2023, 3:31pm UTC](https://discuss.elastic.co/t/field-value-factor-use-max-of-score/327971/4 "2023-03-18T15:31:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 15, 2023, 3:32pm UTC](https://discuss.elastic.co/t/field-value-factor-use-max-of-score/327971/5 "2023-04-15T15:32:05Z")

</div>

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