Limiting aggregation input size

Is it possible to limit the number of documents to aggregate?
I wish to optimize the number of script executions specified in the "include" field.

POST /stats/_search
{
  "size":0,
  "query": {
     "bool" : {
        "must": [{"query_string" : {"query": "something"}},...]
     }
  },
  "aggs": {
    "terms": {
      "field": "events",
      "include" : "http.*",
    }
  }
}

See the sampler or diversified sampler aggregation

1 Like