# Using cardinality on a field after bucketing

**URL:** <https://discuss.elastic.co/t/using-cardinality-on-a-field-after-bucketing/107066>\
**Category:** Elasticsearch\
**Created:** [November 9, 2017, 4:21pm UTC](https://discuss.elastic.co/t/using-cardinality-on-a-field-after-bucketing/107066 "2017-11-09T16:21:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtalmi](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jtalmi](https://discuss.elastic.co/u/jtalmi)\
**Post date:** [November 9, 2017, 4:21pm UTC](https://discuss.elastic.co/t/using-cardinality-on-a-field-after-bucketing/107066/1 "2017-11-09T16:21:58Z")

</div>

Hi,

I have an index of user events and I want to calculate the number of active users. Counting the number of users with at least 1 event in the last 30 days is easy, but I would like to count users with events on multiple days.

If I bucket by user and run cardinality on the 'date' field, this should count the number of unique days on which a user has logged events. So users with 1+ events on a single day would be 1, whereas users with 2+ events spread over multiple days would have \>1. Then I can just filter out the users who only have a 1.

I am not really sure how to do this in ES, or if it's possible. Any help would be appreciated.

Thanks.

---

<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:** [December 7, 2017, 4:22pm UTC](https://discuss.elastic.co/t/using-cardinality-on-a-field-after-bucketing/107066/2 "2017-12-07T16:22:37Z")

</div>

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