# Elasticsearch Range Aggregation is including upper limit excluding lower limit

**URL:** <https://discuss.elastic.co/t/elasticsearch-range-aggregation-is-including-upper-limit-excluding-lower-limit/221185>\
**Category:** Elasticsearch\
**Created:** [February 27, 2020, 9:14am UTC](https://discuss.elastic.co/t/elasticsearch-range-aggregation-is-including-upper-limit-excluding-lower-limit/221185 "2020-02-27T09:14:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarungargbtp2612](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tarungargbtp2612/32/45903_2.png) [@tarungargbtp2612](https://discuss.elastic.co/u/tarungargbtp2612)\
**Post date:** [February 27, 2020, 9:14am UTC](https://discuss.elastic.co/t/elasticsearch-range-aggregation-is-including-upper-limit-excluding-lower-limit/221185/1 "2020-02-27T09:14:34Z")

</div>

I am using the following query:

```auto
{
    "aggs": {
    "profiles": {
      "nested": {
        "path": "profiles"
      },
      "aggs": {
        "ctc": {
          "filter": {
            "range": {
              "profiles.current_employment.usd_ctc": {
                "gte": 17266.176,
                "lte": 17266.176
              }
            }
          },
          "aggs": {
            "filtered_aggs": {
              "aggs": {
                "users_count": {
                  "reverse_nested": {}
                }
              },
              "range": {
                "ranges": [
                  {
                    "to": 17266.176,
                    "from": 8633.088
                  },
                  {
                    "to": 25899.264,
                    "from": 17266.176
                  }
                ],
                "field": "profiles.current_employment.usd_ctc"
              }
            }
          }
        }
      }
    }
  }
}

```

And buckets I am getting:

```auto
"aggregations" : {
    "profiles" : {
      "doc_count" : 58457141,
      "ctc" : {
        "doc_count" : 684,
        "filtered_aggs" : {
          "buckets" : [
            {
              "key" : "8633.088-17266.176",
              "from" : 8633.088,
              "to" : 17266.176,
              "doc_count" : 684,
              "users_count" : {
                "doc_count" : 651
              }
            },
            {
              "key" : "17266.176-25899.264",
              "from" : 17266.176,
              "to" : 25899.264,
              "doc_count" : 0,
              "users_count" : {
                "doc_count" : 0
              }
            }
          ]
        }
      }
    }
  }

```

The first bucket should have 0 count but it is not the case. Please help.

---

<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:** [March 26, 2020, 9:14am UTC](https://discuss.elastic.co/t/elasticsearch-range-aggregation-is-including-upper-limit-excluding-lower-limit/221185/2 "2020-03-26T09:14:37Z")

</div>

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