# Limit bucket size in aggregation results

**URL:** <https://discuss.elastic.co/t/limit-bucket-size-in-aggregation-results/110731>\
**Category:** Elasticsearch\
**Created:** [December 7, 2017, 6:27pm UTC](https://discuss.elastic.co/t/limit-bucket-size-in-aggregation-results/110731 "2017-12-07T18:27:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![babu.ganesh0708](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babu.ganesh0708/32/68550_2.png) [@babu.ganesh0708](https://discuss.elastic.co/u/babu.ganesh0708)\
**Post date:** [December 7, 2017, 6:27pm UTC](https://discuss.elastic.co/t/limit-bucket-size-in-aggregation-results/110731/1 "2017-12-07T18:27:45Z")

</div>

Hi All,

I am trying to limit to the bucket count in the aggregation results and below is the query I am using,

```
GET metricbeat_0/_search
{
   "query": {
      "range": {
         "timestamp": {
            "gte": "2017-09-29 17:57:04.437",
            "lte": "2017-12-07 09:16:44.399"
         }
      }
   },
   "aggs": {
      "bucket_time": {
         "date_histogram": {
            "field": "timestamp",
            "interval": "5m",
            "order": {
               "_key": "desc"
            }
         },
         "aggs": {
            "server_stats": {
               "avg": {
                  "field": "metricbeat_system_process_memory_size"
               }
            }
         }
      }
   }
}

```

I want to limit the size of the bucket count and for ex:- If I defined the size: 10 the bucket should only contains ten records.

How to limit the bucket count in the above query?

Please kindly share your thoughts.

Thanks,  
Ganeshbabu R

---

<div class="post-metadata">

**Author:** ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)\
**Post date:** [December 15, 2017, 11:39am UTC](https://discuss.elastic.co/t/limit-bucket-size-in-aggregation-results/110731/2 "2017-12-15T11:39:48Z")

</div>

Hi Ganesh,

The date\_histogram will always return all buckets. That said you could use the range query you defined above to limit the size of the date\_histogram agg.

For example, your interval is set to 5m, them if you want it to have size 10 you range interval must be 50 minutes.

Does it make sense?

Cheers,  
LG

---

<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:** [January 12, 2018, 11:40am UTC](https://discuss.elastic.co/t/limit-bucket-size-in-aggregation-results/110731/3 "2018-01-12T11:40:22Z")

</div>

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