ES query for max id giving me results in scientific notation instead of long, How to fix this?

Viewed 286

Running this query to get Aggregate for max id

   POST /index/_search?size=0
    {
            "size": 0,
            "aggs": {
              "maxid": {
                "max": { "field": "id"}
              }
            }
    }

The Result I am getting:

aggregations” : {
    “maxuid” : {
      “value” : 8.017010958E9
    }
  }

The result I want:

aggregations” : {
    “maxuid” : {
      “value” : 8017010958
    }
  }
1 Answers

This happens because all aggregations convert number fields into double before doing any aggregation.

You can convert the result without losing any precision upto longs with absolute value less than 2^53. So you do not have to worry about it.

If you do not want to process anything after getting the result, you can do a query with sort by id and size 1 to get the largest id.

{
    "query": {
        "match_all": {}
    },
    "size" : 1,
    "sort" : [{
         "id" : { "order" : "desc" }
    }]
}

Source

Related