# Bucketize document score based on values of an attribute

**URL:** <https://discuss.elastic.co/t/bucketize-document-score-based-on-values-of-an-attribute/18380>\
**Category:** Elasticsearch\
**Created:** [June 28, 2014, 1:18am UTC](https://discuss.elastic.co/t/bucketize-document-score-based-on-values-of-an-attribute/18380 "2014-06-28T01:18:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsa](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@bsa](https://discuss.elastic.co/u/bsa)\
**Post date:** [June 28, 2014, 1:18am UTC](https://discuss.elastic.co/t/bucketize-document-score-based-on-values-of-an-attribute/18380/1 "2014-06-28T01:18:19Z")

</div>

I am writing a function in a function\_score query to alter the default  
score of a document based on the value of an attribute. For example, if an  
attribute "status" has two values "open" and "closed" and I want search  
hits with "open" status to be ranked higher than those with "closed"  
status.

My current idea is to scale the score of a search hit to a scale of 0 to  
(0.5_max\_score) for records with "closed" status and scale of  
(0.5_max\_score to max\_score) for records with "open" status. This will make  
open records to rank higher than closed records. This requires max\_score to  
be known in the function script.

Questions -

1. How to access max\_score of a search hit in the function script?
2. Is there an alternate way to achieve the above ranking?

--  
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/0eb4594c-4f7f-48b6-8521-1cefe83f0e81%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0eb4594c-4f7f-48b6-8521-1cefe83f0e81%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![drull](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@drull](https://discuss.elastic.co/u/drull)\
**Post date:** [February 5, 2015, 5:42pm UTC](https://discuss.elastic.co/t/bucketize-document-score-based-on-values-of-an-attribute/18380/2 "2015-02-05T17:42:11Z")

</div>

I have almost same problem. Have you found any solution?

--  
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/6642d644-fa7c-4e74-9b5e-865e82636eb1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6642d644-fa7c-4e74-9b5e-865e82636eb1%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, 12:34am UTC](https://discuss.elastic.co/t/bucketize-document-score-based-on-values-of-an-attribute/18380/3 "2017-07-06T00:34:42Z")

</div>


