# Range aggrigation problem ES 5.2

**URL:** <https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871>\
**Category:** Elasticsearch\
**Created:** [February 21, 2017, 12:21pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871 "2017-02-21T12:21:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlkmhd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mlkmhd/32/22385_2.png) [@mlkmhd](https://discuss.elastic.co/u/mlkmhd)\
**Post date:** [February 21, 2017, 12:21pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/1 "2017-02-21T12:21:59Z")

</div>

Hi,  
I have a problem with `range aggrigation`.  
this is my query :

```
{
  "query": { ... },
  "aggs": {
    "location_bulks": {
      "range": {
        "field": "lc",
        "ranges": [
          {
            "from": 98210000,
            "to": 98219999
          }
        ]
      },
      "aggs": {
        "locations_range": {
          "histogram": {
            "field": "lc",
            "interval": 1000,
            "min_doc_count": 1,
            "order": {
              "_count": "desc"
            }
          }
        }
      }
    }
  }
}

```

but in the aggrigation results there is some bucket out of range values. is it a bug?

```
{
  "took": 11,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": { ... },
  "aggregations": {
    "location_bulks": {
      "buckets": [
        {
          "key": "9.821E7-9.8219999E7",
          "from": 98210000,
          "to": 98219999,
          "doc_count": 12026,
          "locations_range": {
            "buckets": [
              {
                "key": 98210000,
                "doc_count": 3639
              },
              {
                "key": 98212000,
                "doc_count": 2014
              },
              {
                "key": 98218000,
                "doc_count": 1997
              },
              {
                "key": 98313000, // <==== out of range
                "doc_count": 11
              },
              {
                "key": 98263000, // <==== out of range
                "doc_count": 10
              },
              {
                "key": 98260000, // <==== out of range
                "doc_count": 9
              },
              {
                "key": 98708000, // <==== out of range
                "doc_count": 8
              },
              {
                "key": 98211000, // <==== out of range
                "doc_count": 7
              },
            ]
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 21, 2017, 2:27pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/2 "2017-02-21T14:27:43Z")

</div>

What is the mapping for this field?

---

<div class="post-metadata">

**Author:** ![mlkmhd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mlkmhd/32/22385_2.png) [@mlkmhd](https://discuss.elastic.co/u/mlkmhd)\
**Post date:** [February 21, 2017, 2:34pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/3 "2017-02-21T14:34:40Z")

</div>

mapping:

```
"lc" : {
    "type" : "long"
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 21, 2017, 3:29pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/4 "2017-02-21T15:29:45Z")

</div>

@jpountz does this ring a bell?  
Precision issue with longs?

---

<div class="post-metadata">

**Author:** ![mlkmhd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mlkmhd/32/22385_2.png) [@mlkmhd](https://discuss.elastic.co/u/mlkmhd)\
**Post date:** [February 21, 2017, 3:35pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/5 "2017-02-21T15:35:43Z")

</div>

I find out a document that has two `lc` (`lc` is name of field that I aggregated) value. (one of them in range and one of them out of range)

```
"lc": [
        98210000,
        98260000
      ]
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 21, 2017, 4:04pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/6 "2017-02-21T16:04:21Z")

</div>

Ha! That explains then...

---

<div class="post-metadata">

**Author:** ![mlkmhd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mlkmhd/32/22385_2.png) [@mlkmhd](https://discuss.elastic.co/u/mlkmhd)\
**Post date:** [February 21, 2017, 4:13pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/7 "2017-02-21T16:13:49Z")

</div>

How can I only get `doc_count` of in range values?  
is there `from` and `to` for `histogram` aggregation?

---

<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 21, 2017, 4:13pm UTC](https://discuss.elastic.co/t/range-aggrigation-problem-es-5-2/75871/8 "2017-03-21T16:13:57Z")

</div>

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