It seems that elasticsearch is rounding scores that comes from function_score. I have a complex query that use function_score and has_child to sort parent depending on a creation_date date of a child (therefore I can't use sort). The return scores are rounded even in a very simple scenario:
{
"query": {
"function_score": {
"boost_mode": "replace",
"functions": [
{
"script_score": {
"script": "doc[\"creation_date\"].value"
}
}
]
}
},
"script_fields": {
"date": {
"script": "doc['creation_date'].date"
},
"value": {
"script": "doc['creation_date'].value"
}
}
}
I tried with different script_score :
doc["creation_date"].date.getMillis()
or (creation_date_ts
is the same date as a unixtimestamp
)
doc["creation_date_ts"].value
or even a literal int:
1416398851930
But whatever I use I end up with rounded scores.
Here is an example of the results :
{
"_id": "nyrhhh5z",
"_index": "xxx-1416487038",
"_score": 1416398900000,
"_type": "xxx",
"fields": {
"date": [
"2014-11-19T12:07:31.930Z"
],
"value": [
1416398851930
]
}
}
The _score
should be 1416398851930
(value) be gets rounded to 1416398900000
.
It is a normal behavior, is it documented somewhere (I've searched)? and it there a way to force elasticsearch not to round the scores.
Version of elasticsearch is 1.3.2 (ubuntu 14.04).
The
_score
value is internally hard coded as a float which can only accurately represent integers up to the value 134217728. Therefore, if you want to make use, in the scoring function, of a field stored as a number larger than that, it will overflow the buffer and be truncated. See this github issue