# Range Aggregation is not working properly for float fields

**URL:** <https://discuss.elastic.co/t/range-aggregation-is-not-working-properly-for-float-fields/281908>\
**Category:** Elasticsearch\
**Created:** [August 19, 2021, 6:41am UTC](https://discuss.elastic.co/t/range-aggregation-is-not-working-properly-for-float-fields/281908 "2021-08-19T06:41:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ofir\_Edi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofir_edi/32/78181_2.png) [@Ofir\_Edi](https://discuss.elastic.co/u/Ofir_Edi)\
**Post date:** [August 19, 2021, 6:41am UTC](https://discuss.elastic.co/t/range-aggregation-is-not-working-properly-for-float-fields/281908/1 "2021-08-19T06:41:57Z")

</div>

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:

```json
PUT test1
{
  "settings": {
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "amount": {
        "type": "float"
      }
    }
  }
}

```

1. insert a doc:

```json
PUT test1/_doc/1
{
  "amount": 0.04
}

```

1. make range aggregation with limits of 0.04

```json
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:

```json
{
  "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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 16, 2021, 6:42am UTC](https://discuss.elastic.co/t/range-aggregation-is-not-working-properly-for-float-fields/281908/2 "2021-09-16T06:42:29Z")

</div>

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