Confusion on Aggregation Sum Datatype

I am missing something w/ ES Sum Aggregations. I want to sum a field that is mapped to as an integer vs a float. I specifically would like the resulting sum value to be an integer too.

I have simplified my query and am just now using a script to return a hard coded integer(1) just to eliminate any issues w/ my doc type mapping. Even in this simple case the result is a float. Query:

GET /dogs/_search
  "aggregations": {
    "total": {
      "sum": {
        "script" : {
                   "source": "1"


And here is the result:

  "aggregations" : {
    "total" : {
      "value" : 108.0

Is there anyway to make that total be an Integer? Any links to further reading would help. I searched a ton on this in the google machine and got nothing relevant, so i just must be missing something.


Yeah, unfortunately that's just how the agg framework functions at the moment. :frowning: There's a ticket here you can follow:

Basically, the entire agg framework converts all numeric values to double first before proceeding with computations. So the final output will be in double space regardless of what the input field type is.

There were some technical reasons for this in the past, but those have since been removed so we may be able to make aggs operate with the same type as their field. It's still tricky though, since searches may span shards with different data types and that would cause an implicit "up-conversion" event.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.