# Limiting aggregation input size

**URL:** https://discuss.elastic.co/t/limiting-aggregation-input-size/199019
**Category:** Elasticsearch
**Created:** [September 11, 2019, 6:56am UTC](https://discuss.elastic.co/t/limiting-aggregation-input-size/199019 "2019-09-11T06:56:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Yonatan\_Omer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yonatan_omer/32/42450_2.png) [@Yonatan\_Omer](https://discuss.elastic.co/u/Yonatan_Omer)
#### Post date: [September 11, 2019, 6:56am UTC](https://discuss.elastic.co/t/limiting-aggregation-input-size/199019/1 "2019-09-11T06:56:15Z")

</div>

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.

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

```

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [September 11, 2019, 8:25am UTC](https://discuss.elastic.co/t/limiting-aggregation-input-size/199019/2 "2019-09-11T08:25:39Z")

</div>

See the [sampler](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html) or [diversified sampler](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html) aggregation

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 9, 2019, 8:25am UTC](https://discuss.elastic.co/t/limiting-aggregation-input-size/199019/3 "2019-10-09T08:25:39Z")

</div>

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