# Normalize a script\_score based on returned doc fields

**URL:** https://discuss.elastic.co/t/normalize-a-script-score-based-on-returned-doc-fields/201693
**Category:** Elasticsearch
**Created:** [September 30, 2019, 7:28pm UTC](https://discuss.elastic.co/t/normalize-a-script-score-based-on-returned-doc-fields/201693 "2019-09-30T19:28:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rpanczer](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rpanczer](https://discuss.elastic.co/u/rpanczer)
#### Post date: [September 30, 2019, 7:29pm UTC](https://discuss.elastic.co/t/normalize-a-script-score-based-on-returned-doc-fields/201693/1 "2019-09-30T19:29:00Z")

</div>

I am trying to change the \_score of documents by normalizing all returned `doc['relevancy'].value` fields by the max `doc['relevancy'].value` of the result set. I also would like to multiple this result by the Max Elastic Search score found in `hits.total.value`.

Is this type of calculation possible? I can't seem to find something like it in the documentation.

```auto
curl -X GET "localhost:9200/products/_search?pretty&size=20" -H 'Content-Type: application/json' -d'
{
  "query": {
    "function_score": {
      "query": {
        "multi_match" : {
          "query": "KQ2", 
          "fields": ["item_id", "item_desc"] 
        }
      },
      "script_score" : {
          "script": "(doc[\u0027relevancy\u0027].value / max_of_relevancy_field) * _max_score"
      },
      "boost_mode": "replace"
    }
  }
}
'

```

---

<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: [October 28, 2019, 7:36pm UTC](https://discuss.elastic.co/t/normalize-a-script-score-based-on-returned-doc-fields/201693/2 "2019-10-28T19:36:05Z")

</div>

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