In the guide I saw an example:
GET /cars/transactions/_search?search_type=count
{
"query":{
"match": {
"make": "ford"
}
},
"aggs":{
"recent_sales": {
"filter": {
"range": {
"sold": {
"from": "now-1M"
}
}
},
"aggs": {
"average_price":{
"avg": {
"field": "price"
}
}
}
}
}
}
This is pretty close to what I want to do, but instead of a range of dates, I just want the 5 most recent results in each bucket, and I want to be able to average the price.
I have tried the limit filter in a bucket, but that doesn't do what I would expect it to do (documents per shard? really?) and it's deprecated anyway.
I also tried to use the top_hits
aggregation but that won't allow me to average the results because it doesn't accept sub-aggregations.
I have tried to apply multiple filters, set size options, and all other sorts of things with no correct results. the closest I seem to be able to find to this problem is
Top N documents with multiple buckets
But I don't actually understand what he's doing and I don't think the terms
aggregator applies since i'm trying to sort and limit by timestamps of which there are many many duplicates. I'm under some time pressure here and it seems like if I was doing this with a traditional SQL query I'd have been done yesterday. Any help is much appreciated.