Getting the list of years of type

I have a type called vehicle_type that has a field called built_year, I want to get a list of years of my vehicles.
I got a list of years with an aggregate (bucket)

{
     "aggs": {
       "years": {
         "terms": {
           "field": "built_year",
           "size": 20
         }
       }
     }
}

Is it possible to get a list of all the years in order (DESC or ASC).

You're close! This is what you want, just use order as well and increase your size.

1 Like