I want to paginate the buckets with "size" and "from" ordered by the "Timestamp" field. I have tried the bucket_sort but it did not work as it expects another sibling aggregation and cannot aggregate on the Timestamp field here. Elasticserch 6.7.2
My sample data is,
[{
"Name": "Event A",
"Timestamp": "2020-02-02T09:45:20.954Z"
},
{
"Name": "Event B",
"Timestamp": "2020-02-04T09:45:20.954Z"
},
{
"Name": "Event C",
"Timestamp": "2020-02-03T09:45:20.954Z"
},
{
"Name": "Event A",
"Timestamp": "2020-02-01T09:45:20.954Z"
},
{
"Name": "Event D",
"Timestamp": "2020-01-15T09:45:20.954Z"
}]
and current result is ordered by the doc_count but I want to order by date. My expected result is,
"buckets": [
{
"key": "Event B",
"doc_count": 1
}
,
{
"key": "Event C",
"doc_count": 1
}
,
{
"key": "Event A",
"doc_count": 2
}
,
{
"key": "Event D",
"doc_count": 1
}
]
Thanks in advance.
Edit 1 -
I have tried the query to get the ordered buckets without "from",
{
"size": 0,
"aggs": {
"eventNames": {
"terms": {
"field": "Name",
"size": 5,
"order": {
"firstOccurredAggs": "desc"
}
},
"aggs": {
"firstOccurredAggs": {
"min": {
"field": "Timestamp"
}
}
}
}
}
}
But I was not able to paginate the results.