Hi,
I have an index with documents that only have 3 fields: id, timestamp and status.
I want to retrieve the newest document for each id, but: if that document's status is equals to "something", then I would like to ignore that bucket completely.
What's the best way to do this?
I was able to retrieve the newest document for each id with the query below but I don't know how to filter buckets based on the document's status.
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"group_by_order_id": {
"terms": {
"field": "id.keyword"
},
"aggs": {
"top_group_hits": {
"top_hits": {
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"size": 1
}
}
}
}
}
}
Thanks,
Alex.