Aggregation with order by integer

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

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

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.

1 Like