# How to filter on unique count aggreagtion

**URL:** <https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737>\
**Category:** Kibana\
**Created:** [December 13, 2018, 12:49pm UTC](https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737 "2018-12-13T12:49:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peppe\_17](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peppe\_17](https://discuss.elastic.co/u/Peppe_17)\
**Post date:** [December 13, 2018, 12:49pm UTC](https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737/1 "2018-12-13T12:49:38Z")

</div>

Hi All,  
I am trying to filter a unique count aggregation for values \>= 1.  
With normal counts, min\_doc\_count works fine. So for example I input string {"min\_doc\_count":2} in the Json input section of the bucket. But when using the unique count metric this does not seem to work. Probably I need to change the Json input, would you know how and if this is possible at all?  
Thanks in advance for your time.

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [December 14, 2018, 1:21am UTC](https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737/2 "2018-12-14T01:21:40Z")

</div>

The min\_doc\_count is going to filter buckets based on the number of documents in that time range and then the metric (unique count) is calculated on top. Instead of a unique count metric would something like a sub bucket using a terms aggregation work instead?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/d/ad563d94e3efbfc8eee701ac3ec0081b25c4b0b4.png)

---

<div class="post-metadata">

**Author:** ![Peppe\_17](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peppe\_17](https://discuss.elastic.co/u/Peppe_17)\
**Post date:** [December 14, 2018, 10:18am UTC](https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737/3 "2018-12-14T10:18:23Z")

</div>

Hi Jon,

thanks very much for your reply. Unfortunately my index does not have any "date" field type so I cannot use aggregation "Date Histogram" as in your screenshot.  
In addition I really need to use the unique count because of the repetition of data in my dataset. An example to try to give the idea of what I want to do:

Data Row A:  
House owner name: Tim  
House location: Zurich  
House type: Villa

Data Row B:  
House owner name: Tim  
House location: Zurich  
House type: Flat

Data Row C:  
House owner name: Tim  
House location: London  
House type: Flat

Data Row D:  
House owner name: Mark  
House location: London  
House type: Villa

I would like to know in how many different cities an house owner has an house.

Tim count would be 2  
Mark count would be 1

But in the final visualization I would like to see only the house owners with an house in more than 1 different city. Basically I would like to see only Tim in my data visualization.  
Obviously ma dataset has much more details and variables so a simple exclusion of the house type field would not work.

Is there a way I can achieve this?  
Sorry in advance if I was not too clear or my questions are dumb, I'm just a beginner 🙂  
Thanks  
Giuseppe

---

<div class="post-metadata">

**Author:** ![Peppe\_17](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peppe\_17](https://discuss.elastic.co/u/Peppe_17)\
**Post date:** [January 7, 2019, 12:55pm UTC](https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737/4 "2019-01-07T12:55:01Z")

</div>

Hello and happy new year everybody

Is there anyone who can help me with my inquiry?

Thanks  
Giuseppe

---

<div class="post-metadata">

**Author:** ![Peppe\_17](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peppe\_17](https://discuss.elastic.co/u/Peppe_17)\
**Post date:** [January 29, 2019, 3:27pm UTC](https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737/6 "2019-01-29T15:27:36Z")

</div>

Hi @mahmoud_016,

many thanks for your kind reply. I will check and let you know if it works for me!

Cheers  
Giuseppe

---

<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 26, 2019, 3:39pm UTC](https://discuss.elastic.co/t/how-to-filter-on-unique-count-aggreagtion/160737/7 "2019-02-26T15:39:09Z")

</div>

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