Hi, what would be the difference between sorting on the top level query vs in the aggs vs doing both? Here is a sample query
{
"size": 0,
"from": 0,
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
211314
]
}
}
]
}
},
"aggs": {
"group_by_id": {
"terms": {
"size": 1,
"field": "id"
},
"aggs": {
"earliest_date": {
"top_hits": {
"size": 1,
"_source": {
"includes": [
"id",
"dateTime.utc",
"dateTime.local"
]
},
"sort": [
{
"dateTime.utc": "asc"
}
]
}
}
}
}
},
"sort": [
{
"dateTime.utc": "asc"
}
]
}
As you can see, the top level query sorts by dateTime.utc and I also sort the top_hits by the same field. Which way would be the appropriate way to retrieve the earliest date possible for each grouping?