# Aggregation with order by integer

**URL:** <https://discuss.elastic.co/t/aggregation-with-order-by-integer/56124>\
**Category:** Elasticsearch\
**Created:** [July 21, 2016, 5:17pm UTC](https://discuss.elastic.co/t/aggregation-with-order-by-integer/56124 "2016-07-21T17:17:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelr](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@samuelr](https://discuss.elastic.co/u/samuelr)\
**Post date:** [July 21, 2016, 5:17pm UTC](https://discuss.elastic.co/t/aggregation-with-order-by-integer/56124/1 "2016-07-21T17:17:26Z")

</div>

hello, I need to make an aggregation and sort the results by an integer field.  
I know how to do with type string, but not with integer.

```
"size": 0, "aggs" : { 
"municipios" : {
    "terms" : { 
        "field" : "doenca", "size":1 }, 
        "aggs": {
            "ages": 
        { "terms": { 
            "field": "age","min_doc_count": 0,
            "order" : { ???? },
            "size" : 0 }
  }} } }

```

Note: There is how to make an aggregation with range for ages?  
for example from 10 to 20, 20 to 30?  
Thank you so much

---

<div class="post-metadata">

**Author:** ![samuelr](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@samuelr](https://discuss.elastic.co/u/samuelr)\
**Post date:** [July 22, 2016, 4:57pm UTC](https://discuss.elastic.co/t/aggregation-with-order-by-integer/56124/2 "2016-07-22T16:57:45Z")

</div>

someone please?  
I'm sorry if the question is very obvious , but I did not find anything about it in the documentation.

---

<div class="post-metadata">

**Author:** ![samuelr](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@samuelr](https://discuss.elastic.co/u/samuelr)\
**Post date:** [July 23, 2016, 4:07pm UTC](https://discuss.elastic.co/t/aggregation-with-order-by-integer/56124/3 "2016-07-23T16:07:50Z")

</div>

i need this:

```
 "Buckets": [
              {
                 "Key": 0,
                 "Doc_count": 0
              },
              {
                 "Key": 1,
                 "Doc_count": 2442
              },
              {
                 "Key": 2
                 "Doc_count": 13428
              },
              {
                 "Key": 3
                 "Doc_count": 8544
              },

```

the key, which would be the age, ordered from smallest to largest.

and using "order" : { "\_term" : "asc" }, in the term age, now its  
returning properly.

there is the answer, if someone has the same doubts.

---

<div class="post-metadata">

**Author:** ![jpcarey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpcarey/32/46668_2.png) [@jpcarey](https://discuss.elastic.co/u/jpcarey)\
**Post date:** [July 23, 2016, 4:51pm UTC](https://discuss.elastic.co/t/aggregation-with-order-by-integer/56124/4 "2016-07-23T16:51:42Z")

</div>

> [@samuelr](#):
>
> Note: There is how to make an aggregation with range for ages? for example from 10 to 20, 20 to 30?

> **[Range aggregation | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html)**

---

<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:** [July 5, 2017, 10:33pm UTC](https://discuss.elastic.co/t/aggregation-with-order-by-integer/56124/5 "2017-07-05T22:33:21Z")

</div>


