Histogram Aggregation: unstable bucket keys with decimal intervals

I'd like to build the histogram on numeric values index as doubles. I want to be able to perform searches on produces buckets but I get inconsistent counts for buckets and search results. Example:

"aggs" : {
    "histogram" : {
        "histogram": {
            "field" : "field_name",
            "interval": 0.2
        }
    }
}

will produce:

  "aggregations" : {
    "histogram" : {
      "buckets" : [
        {
          "key" : 0.4,
          "doc_count" : 7
        },
        {
          "key" : 0.6000000000000001,
          "doc_count" : 53
        }
      ]
   }
}

But when I run range query

"query": {
    "range": {
      "field_name": {
        "gte": 0.4,
        "lt": 0.6000000000000001
      }
    }
  } 

the search result doesn't match the 53 bucket count. Could anyone help me to understand what's happening here? Thank you in advance!

There explanation here on how bucket key is computed and how rounding decides that which value falls in which bucket, will help you clear your doubt.

Thanks for your reply. Indeed, I did go over documentation a couple of times. I can see how values are assigned to the buckets. But where is this fluctuation of 0.00000000001 comes from in the bucket key? And is it really expected that the range search won't work as expected for the calculated buckets? I don't see in documentation an explanation of why the intervals like 0.5 or 0.1 or 1.5 produce stable keys, but anything that is not an increment of 0.5 give this bucket keys as 1.200000000001 or 2.3999999999999. If anyone could someone shed light on it, the help will be greatly appreciated.

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