Limit bucket size in aggregation results

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.

Ganeshbabu R

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?


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