# Keys in range aggregation

**URL:** <https://discuss.elastic.co/t/keys-in-range-aggregation/144309>\
**Category:** Elasticsearch\
**Created:** [August 14, 2018, 9:11am UTC](https://discuss.elastic.co/t/keys-in-range-aggregation/144309 "2018-08-14T09:11:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunaeth](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dunaeth](https://discuss.elastic.co/u/dunaeth)\
**Post date:** [August 14, 2018, 9:11am UTC](https://discuss.elastic.co/t/keys-in-range-aggregation/144309/1 "2018-08-14T09:11:39Z")

</div>

Hi, is there a particular reason behind the choice to use aggregation keys as bucket keys instead of bucket properties when using range aggregation ?

Example :

```
{
    ...
    "aggs": {
        "range0-4": {
            "range": {
                "field": "anyValue",
                "ranges": [
                    {
                        "to": 0.5,
                        "key": "0"
                    },
                    {
                        "from": 0.5,
                        "to": 1.5,
                        "key": "1"
                    },
                    {
                        "from": 1.5,
                        "to": 2.5,
                        "key": "2"
                    },
                    {
                        "from": 2.5,
                        "to": 3.5,
                        "key": "3"
                    },
                    {
                        "from": 3.5,
                        "key": "4"
                    }
                ]
            },
            "aggs": {
                "count": {
                    "global": {}
                }
            }
        }
    }
}

```

Which produces a result like :

```
{
    ...
    "aggregations" : {
        "range0-4" : {
            "buckets": {
                "0" : {...}
                "1" : {...}
                "2" : {...}
                "3" : {...}
                "4" : {...}
            }
        }
    }
}

```

Where many other aggregations return keys this way :

```
{
    ...
    "aggregations" : {
        "terms" : {
            "buckets": [
                {"key" : "0", ...}
                {"key" : "1", ...}
                {"key" : "2", ...}
                {"key" : "3", ...}
                {"key" : "4", ...}
            ]
        }
    }
}
```

---

<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 11, 2018, 9:17am UTC](https://discuss.elastic.co/t/keys-in-range-aggregation/144309/2 "2018-09-11T09:17:43Z")

</div>

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