# Imprecise integer handling in script\_score?

**URL:** <https://discuss.elastic.co/t/imprecise-integer-handling-in-script-score/21922>\
**Category:** Elasticsearch\
**Created:** [January 30, 2015, 3:45pm UTC](https://discuss.elastic.co/t/imprecise-integer-handling-in-script-score/21922 "2015-01-30T15:45:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Urs\_Enke](https://avatars.discourse-cdn.com/v4/letter/u/839c29/32.png) [@Urs\_Enke](https://discuss.elastic.co/u/Urs_Enke)\
**Post date:** [January 30, 2015, 3:45pm UTC](https://discuss.elastic.co/t/imprecise-integer-handling-in-script-score/21922/1 "2015-01-30T15:45:48Z")

</div>

I have a has\_child query (see this posting's bottom) that scores by  
children's most recent timestamps (defined as type "date" in the mapping):  
"script": "doc['p.created'].value"

But instead of the maximum of the actual timestamps, they are somehow  
rounded to a \_score of nearby numbers that differ by 120 or 130 each, at  
least the more recent ones:  
• 1422630910  
• 1422630780  
• 1422630660  
• 1422630530

Suspecting that these integers aren't really handled as such internally, I  
tried subtracting a recent timestamp to get the relevant numbers into a  
smaller and hence more precisely handled range:  
"script": "doc['p.created'].value-1400000000"  
And indeed, the minimum difference between the 'rounded' figures was  
reduced by a factor of 20, to at most 6. While this largely solves the  
problem, it does not do so entirely. Is there a way to get ES to treat  
these figures as 'full' integers? I have tried some type-casting in the  
Groovy expression – without success.

Thanks in advance for any hints!

The full query:  
{  
"query": {  
"has\_child": {  
"type": "p",  
"query": {  
"function\_score": {  
"query": {  
"match\_all": {}  
},  
"boost\_mode": "replace",  
"functions": [  
{  
"script\_score": {  
"script": "_doc['p.created'].value_",  
"lang": "groovy"  
}  
}  
]  
}  
},  
"score\_mode": "_max_"  
}  
}  
}

--  
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/ab476848-3d67-4901-8bf7-affee12a594d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ab476848-3d67-4901-8bf7-affee12a594d%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:35am UTC](https://discuss.elastic.co/t/imprecise-integer-handling-in-script-score/21922/2 "2017-07-06T00:35:38Z")

</div>


