Is it possible to limit retrieved documents based on a sum aggregation?

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?

As a corollary to this, it is possible to only retrieve the first document associated with the aggregation sum crossing a particular threshold, such as every 100 or something?

This likely implies an amount of internal ordering that isn't available, but it's worth a shot....

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.