# Can't figure out how to get bucket count for an aggregation

**URL:** <https://discuss.elastic.co/t/cant-figure-out-how-to-get-bucket-count-for-an-aggregation/114611>\
**Category:** Elasticsearch\
**Created:** [January 8, 2018, 8:30pm UTC](https://discuss.elastic.co/t/cant-figure-out-how-to-get-bucket-count-for-an-aggregation/114611 "2018-01-08T20:30:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [January 8, 2018, 8:30pm UTC](https://discuss.elastic.co/t/cant-figure-out-how-to-get-bucket-count-for-an-aggregation/114611/1 "2018-01-08T20:30:36Z")

</div>

I'm trying to form a query that will get the number of unique IP addresses that have a total of 6 or more documents in a given time range. Here is what I have so far:

```
{
    "query": {
        "bool": {
            "filter": [{
                    "term": {
                        "org_id": 1
                    }
                },
                {
                    "term": {
                        "page.page_type": "post"
                    }
                },
                {
                    "range": {
                        "date": {
                            "gte": this.startDate,
                            "lt": this.endDate
                        }
                    }
                }
            ]
        }
    },
    "aggregations": {
        "pageviews_per_ip": {
            "terms": {
                "field": "ip.address",
                "min_doc_count": 6
            }
        }
    },
    "size": 0
}

```

The problem is that I can't use the cardinality aggregation to count the number of unique IPs because I am using a conditional "min\_doc\_count" which the cardinality agg doesn't support.

How can I calculate the number of docs Elasticsearch should return for this query?

Thank you.

---

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [January 10, 2018, 12:20pm UTC](https://discuss.elastic.co/t/cant-figure-out-how-to-get-bucket-count-for-an-aggregation/114611/2 "2018-01-10T12:20:28Z")

</div>

bump

...are we allowed to bump?

---

<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:** [February 7, 2018, 12:20pm UTC](https://discuss.elastic.co/t/cant-figure-out-how-to-get-bucket-count-for-an-aggregation/114611/3 "2018-02-07T12:20:29Z")

</div>

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