Created
July 26, 2018 13:14
-
-
Save samyranavela/44a4144813fab3a410632a500ae027ca to your computer and use it in GitHub Desktop.
ou can use a top_hits aggregation that groups on the country field, returns 1 doc per group, and orders the docs by the collected date descending: https://stackoverflow.com/questions/29016271/how-to-get-latest-values-for-each-group-with-an-elasticsearch-query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST /test/_search?search_type=count | |
{ | |
"aggs": { | |
"group": { | |
"terms": { | |
"field": "country" | |
}, | |
"aggs": { | |
"group_docs": { | |
"top_hits": { | |
"size": 1, | |
"sort": [ | |
{ | |
"collected": { | |
"order": "desc" | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment