Lets say i have the documents:
{"name": "foo", "size": 1}
{"name": "bar", "size": 10}
{"name": "baz", "size": 2}
{"name": "fred", "size": 5}
I could perform the following aggregation:
POST /my-docs/_search?size=0
{
"aggs": {
"total": {
"sum": {
"field": "size"
}
}
}
}
Which is all well and good.
But what if I want to retrieve documents until the aggregate "total" value is >= 13? In that case, I would only want to get the first 3 documents. Is there some way to accomplish this?