# Custom score using the max and the min of two fields

**URL:** https://discuss.elastic.co/t/custom-score-using-the-max-and-the-min-of-two-fields/10951
**Category:** Elasticsearch
**Created:** [February 28, 2013, 12:19pm UTC](https://discuss.elastic.co/t/custom-score-using-the-max-and-the-min-of-two-fields/10951 "2013-02-28T12:19:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Davide\_Non\_Vattelape](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davide_non_vattelape/32/2630_2.png) [@Davide\_Non\_Vattelape](https://discuss.elastic.co/u/Davide_Non_Vattelape)
#### Post date: [February 28, 2013, 12:19pm UTC](https://discuss.elastic.co/t/custom-score-using-the-max-and-the-min-of-two-fields/10951/1 "2013-02-28T12:19:43Z")

</div>

hi all,

I need to redefine the score in my search result.  
The formula I want to use is something like:

"script" : "0.5 \* ((doc['priceMin'].value - priceMin) / (priceMax -  
priceMin)) + 0.5 \*(1 - ((doc['rank'].value - rankMin) / (rankMin -  
rankMax)))",  
"params" : {  
"rankMin" : 1,  
"priceMin" : 1,  
"rankMax" : 5,  
"priceMax" : 130  
}

But I want replace the params with calculated value, where rankMin and  
priceMin are the min values for related fields in my index, and rankMax and  
priceMax are the max values for related fields in my index

Someone know how I can do it?

thanks,  
Davide

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [March 1, 2013, 12:41pm UTC](https://discuss.elastic.co/t/custom-score-using-the-max-and-the-min-of-two-fields/10951/2 "2013-03-01T12:41:37Z")

</div>

> But I want replace the params with calculated value, where rankMin and  
> priceMin are the min values for related fields in my index, and  
> rankMax and priceMax are the max values for related fields in my index

First you'll need to calculate those values using a statistics facet,  
then you can pass them as parameters.

You can't do it all in one request

clint

> Someone know how I can do it?
> 
> thanks,  
> Davide
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:48am UTC](https://discuss.elastic.co/t/custom-score-using-the-max-and-the-min-of-two-fields/10951/3 "2017-07-06T02:48:50Z")

</div>


