Range Aggregation is not working properly for float fields

Hi,
According to the documentation range aggreagation creates buckets where from in inclusive and to is exclusive. when working with float fields Elasticsearch seem to work vise versa and classify to the wrong bucket. In order to reproduce:

  1. create index with float field:
PUT test1
{
  "settings": {
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "amount": {
        "type": "float"
      }
    }
  }
}
  1. insert a doc:
PUT test1/_doc/1
{
  "amount": 0.04
}
  1. make range aggregation with limits of 0.04
POST test1/_search
{
  "size": 0, 
  "aggs": {
    "testRange": {
      "range": {
        "field": "amount",
        "ranges": [
          {
            "from": 0.01,
            "to": 0.04
          },
          {
            "from": 0.04,
            "to": 0.06
          }
        ]
      }
    }
  }
}

the result i'm getting is that the doc belongs to 0.01-0.04 bucket and not to 0.04-0.06 bucket:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "testRange" : {
      "buckets" : [
        {
          "key" : "0.01-0.04",
          "from" : 0.01,
          "to" : 0.04,
          "doc_count" : 1
        },
        {
          "key" : "0.04-0.06",
          "from" : 0.04,
          "to" : 0.06,
          "doc_count" : 0
        }
      ]
    }
  }
}

I tested with Integers and it seems to be fine but for floats the aggregation not behaving like in the documentation. Any advices?

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