# How to get elasticsearch minimum buckets count

**URL:** <https://discuss.elastic.co/t/how-to-get-elasticsearch-minimum-buckets-count/139739>\
**Category:** Elasticsearch\
**Created:** [July 12, 2018, 11:24am UTC](https://discuss.elastic.co/t/how-to-get-elasticsearch-minimum-buckets-count/139739 "2018-07-12T11:24:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKumarMN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skumarmn/32/27537_2.png) [@SKumarMN](https://discuss.elastic.co/u/SKumarMN)\
**Post date:** [July 12, 2018, 11:24am UTC](https://discuss.elastic.co/t/how-to-get-elasticsearch-minimum-buckets-count/139739/1 "2018-07-12T11:24:46Z")

</div>

I want to get results on an aggregation where buckets.length (number / count of buckets) has a minimum count, kind of like HAVING in SQL.

(In this particular scenario site visitors who have visited at-least 5 different days.)

A portion of my query:

```
 "aggs": {
"site_visitors": {
    "aggs": {
        "users": {
            "terms": {
                "field": "user_id",
                "size": 0
            },
            "aggs": {
                "daily_counts": {
                    "date_histogram": {
                        "field": "timestamp",
                        "interval": "1d"
                    }
                }
            }
        }
    }
}

```

}  
Here we have a bucket with 5 results (buckets.length). Most buckets won't have 5 or more results and I don't want all of those.

```
 {
 "key": 123456,
 "doc_count": 10,
 "days_count": {
    "buckets": [
         {
            "key_as_string": "2017-04-05T00:00:00.000Z",
            "key": 1491350400000,
            "doc_count": 2
         },
         {
            "key_as_string": "2017-04-22T00:00:00.000Z",
            "key": 1492819200000,
            "doc_count": 1
         },
         {
            "key_as_string": "2017-04-25T00:00:00.000Z",
            "key": 1493078400000,
            "doc_count": 4
         },
         {
            "key_as_string": "2017-04-30T00:00:00.000Z",
            "key": 1493510400000,
            "doc_count": 2
         },
         {
            "key_as_string": "2017-05-04T00:00:00.000Z",
            "key": 1493856000000,
            "doc_count": 1
         }
    ]
 }

```

}

I want to get results that ONLY have at-least 5 results or more (eg: gte) in each bucket - not the doc\_count, but the buckets.length.

Is there a way to do this?

---

<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:** [August 9, 2018, 11:24am UTC](https://discuss.elastic.co/t/how-to-get-elasticsearch-minimum-buckets-count/139739/2 "2018-08-09T11:24:47Z")

</div>

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