The handling of integer/float numbers is something that only java devs are aware of. Dividing integers may lead to unexpected results if you do not know how java is handling this.
See this example
PUT foo/bar/1
{
"foo" : 5,
"bar" : 10
}
# returns 0
GET foo/_search
{
"script_fields": {
"calced": {
"script": {
"source" : "doc['foo'].value / doc['bar'].value"
}
}
}
}
# returns 0.5
GET foo/_search
{
"script_fields": {
"calced": {
"script": {
"source" : "(doc['foo'].value + 0.0) / doc['bar'].value"
}
}
}
}
I may have missed where this is documented, which we should do (or maybe more prominently, as I havent found it after 5 minutes with our search).
Ideally we should do the right thing[tm], which is probably super hard to do, so probably this will end up in some documentation?
Most major languages I know of do integer truncation. Why do you think this is specific to java? IMO there is nothing to document here.
we will need to fix documentation here to properly reflect how division works and also how it differs from groovy and mention less that painless resembles groovy despite having a few similarities. I'll come up with a PR
reflect how division works and also how it differs from groovy
I disagree. We should not litter painless docs with "differences from groovy". Otherwise it opens us to to documenting differences between any other language.
This documentation exists:
https://www.elastic.co/guide/en/elasticsearch/painless/master/_operators.html
Under the division operator, one of the first sentences is the following:
"Integer division will drop the remainder of the resultant value. "
Most helpful comment
Most major languages I know of do integer truncation. Why do you think this is specific to java? IMO there is nothing to document here.