# How to normalize score when combining regular query and function\_score?

**URL:** https://discuss.elastic.co/t/how-to-normalize-score-when-combining-regular-query-and-function-score/19323
**Category:** Elasticsearch
**Created:** [August 18, 2014, 1:52pm UTC](https://discuss.elastic.co/t/how-to-normalize-score-when-combining-regular-query-and-function-score/19323 "2014-08-18T13:52:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JohnnyM](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@JohnnyM](https://discuss.elastic.co/u/JohnnyM)
#### Post date: [August 18, 2014, 1:52pm UTC](https://discuss.elastic.co/t/how-to-normalize-score-when-combining-regular-query-and-function-score/19323/1 "2014-08-18T13:52:51Z")

</div>

First of all kudos on the awesome job everyone here is doing!

I was wondering if you guys can help me solve this puzzle:

Also available on stack  
overflow: [http://stackoverflow.com/questions/25361795/elasticsearch-how-to-normalize-score-when-combining-regular-query-and-function](http://stackoverflow.com/questions/25361795/elasticsearch-how-to-normalize-score-when-combining-regular-query-and-function)

Idealy what I am trying to achieve is to assign weights to queries such  
that query1 constitutes 30% of the final score and query2 consitutes other  
70%, so to achieve the maximum score a document has to have highest  
possible score on query1 and query2. My study of the documentation did not  
yield any hints as to how to achieve this so lets try to solve a simpler  
problem.

Consider a query in following form:

{  
"query": {  
"bool": {  
"should": [  
{  
"function\_score": {  
"query": {"match\_all": {}},  
"script\_score": {  
"script": "\<some\_script\>",  
}  
}  
},  
{  
"match": {  
"message": "this is a test"  
}  
}  
]  
}  
}  
}

The script can return an arbitrary number (think-\> it can return something  
like 12392002).

How do I make sure that the result from the script will not dominate the  
overall score? (my experiments using explain show that this indeed can  
happen very often)

Is there any way to normalize it? For example instead of script score  
return the ratio to max\_script\_score (achieved by document with highest  
score)?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2179ed93-575c-47d5-a13a-42d1e2244baa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2179ed93-575c-47d5-a13a-42d1e2244baa%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 1:07am UTC](https://discuss.elastic.co/t/how-to-normalize-score-when-combining-regular-query-and-function-score/19323/2 "2017-07-06T01:07:57Z")

</div>


