Consider below is the 2 documents got after aggregation , now i need to sort on the documents.
Document 1:
{
'startDate' :'2023-02-01',
'endDate' : '2022-02-01'
}
Documet 2 :
{
'endDate' : '2024-02-01'
}
Now i should receive the 2nd document as result after sorting.
Below is the query i am using
{
"groupBy-top-hits": {
"top_hits": {
"sort": [
{
"startDate": {
"order": "desc"
}
},
{
"endDate": {
"order": "desc"
}
}
],
"size": 1
}
}
}
But its returning the 1st document. Query should be if either of the key is present use that for sorting, but its not working that way. Suggest if any query needs to be changed.