# Maximum score of a field in script score - ElasticSearch

**URL:** https://discuss.elastic.co/t/maximum-score-of-a-field-in-script-score-elasticsearch/76047
**Category:** Elasticsearch
**Created:** [February 22, 2017, 2:14pm UTC](https://discuss.elastic.co/t/maximum-score-of-a-field-in-script-score-elasticsearch/76047 "2017-02-22T14:14:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![M.Prabha\_karan](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@M.Prabha\_karan](https://discuss.elastic.co/u/M.Prabha_karan)
#### Post date: [February 22, 2017, 2:14pm UTC](https://discuss.elastic.co/t/maximum-score-of-a-field-in-script-score-elasticsearch/76047/1 "2017-02-22T14:14:08Z")

</div>

I'm using ElasticSearch 2.4.0 . Using the script\_score, I'm calculating custom score like

'{"script":"return ( ((doc.field\_a.value)\* 0.5) + (\_score \* 0.5) );"}'

I want something like (some normalisation effect on the field\_a value):

'max\_score = doc.field\_a.values.max(); return ( ((doc.field\_a.value)\* 0.5)/max\_score + (\_score \* 0.5) );'

Any help appreciated.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [February 27, 2017, 8:28am UTC](https://discuss.elastic.co/t/maximum-score-of-a-field-in-script-score-elasticsearch/76047/2 "2017-02-27T08:28:53Z")

</div>

Hey,

I could not extract from this post what your actual problem is. Can you extend on that? Is it the score calculation or the results? Can you also take your time and create a reproducible example?

--Alex

---

<div class="post-metadata">

### Author: ![M.Prabha\_karan](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@M.Prabha\_karan](https://discuss.elastic.co/u/M.Prabha_karan)
#### Post date: [February 27, 2017, 10:41am UTC](https://discuss.elastic.co/t/maximum-score-of-a-field-in-script-score-elasticsearch/76047/3 "2017-02-27T10:41:57Z")

</div>

Thank you for your reply 🙂

I want to mix up the default '\_score' with a field value in the doc(by some weights). I want to normalise the field value effect by finding maximum of field value in the filtered result.

_curl localhost:9200/index\_name/type/\_search -d'{"\_source":false,"query":{"function\_score":{"query":{"filtered":{"filter":{"bool":{"must":[{"bool":{"should":[{"terms":{"ids":["6","15","5"]}}]}}},{"range":{"count\_on\_hand":{"gte":1}}}],"must\_not":[],"should":[]}}}},"script\_score":{"script":"max\_score=doc.field\_a.values.max();return (((doc.field\_a.value) 0.5)/max\_score + (\_score \* 0.5));"},"boost\_mode":"replace"}},"from":0,"size":12}'_\*

For eg: The field\_a contains value from 1 to 100000. After the filters, if the max\_score of the field is 5000, then  
by the above formula, the document contains the max\_score & high relevancy will be on the top. and followed by the rest of the documents.

---

<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: [March 27, 2017, 10:42am UTC](https://discuss.elastic.co/t/maximum-score-of-a-field-in-script-score-elasticsearch/76047/4 "2017-03-27T10:42:03Z")

</div>

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