I have documents in my index which have a nested object locations
in them.
"locations": [
{
"name": "California",
"coordinates": {
"lat": 36.78,
"long": -119.42
}
}, ...
]
I have written a terms aggregation to create buckets for location names that appear in the dataset:
"aggs": {
"global": {
"nested": {
"path": "locations"
},
"aggs":{
"locations": {
"terms": {
"field": "locations.name.keyword"
}
}
}
}
}
What I would like to do is create buckets for the full location object, so that I can use both the name and the coordinates of the location in my code.
Is there something like a terms aggregation that works on an object rather than just a keyword?
Or (as the coordinates are always the same for the same location) is it possible to return the coordinates of the first location for each bucket along with the count?