# Unique filter in Data Table visualisation

**URL:** https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306
**Category:** Kibana
**Created:** [January 8, 2020, 9:13pm UTC](https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306 "2020-01-08T21:13:16Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ravnica1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravnica1/32/60509_2.png) [@ravnica1](https://discuss.elastic.co/u/ravnica1)
#### Post date: [January 8, 2020, 9:13pm UTC](https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306/1 "2020-01-08T21:13:16Z")

</div>

Hello

Given the following set of documents:

"eventType":"Added",  
"movieId":1,  
"[user":"Jane.Blogs@gmail.com](mailto:user%22:%22Jane.Blogs@gmail.com)"  
"name":"Terminator",  
"userId":1,  
"eventDate":"01-01-2020"

"eventType":"Viewed",  
"movieId":1,  
"[user":"Jane.Blogs@gmail.com](mailto:user%22:%22Jane.Blogs@gmail.com)",  
"name":"Terminator",  
"userId":1,  
"eventDate":"02-01-2020"

"eventType":"Viewed",  
"movieId":1,  
"[user":"Jane.Blogs@gmail.com](mailto:user%22:%22Jane.Blogs@gmail.com)",  
"name":"Terminator",  
"userId":1,  
"eventDate":"03-01-2020"

I am trying to create a Data Table visualisation that will have 2 metrics aggregated by email address as in the following example:

............email ................... added viewed  
[Jane.Blogs@gmail.com](mailto:Jane.Blogs@gmail.com) ........1 .......... 1

So the count for a viewed should be distinct/unique for a movie.

I can easily create aggregation to count all views but have not being able to figure out how to aggregate the distinct values in viewed column.

Any help will be greatly appreciated

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [January 9, 2020, 8:53pm UTC](https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306/2 "2020-01-09T20:53:37Z")

</div>

It looks like your `Added` and `Viewed` columns have value of the movie ID. But in the data, "added" is a different event type than "viewed", and a document won't have both values. The aggregation works by making groups and splitting the groups into rows, so "added" and "viewed" will be in different rows.

Would this work?

- **First bucket:** Aggregate the documents by `user` terms:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/b/2b2e1fee8aa96dc9531c644cd71ba629393cfe47.png)
- **Second bucket:** Sub-aggregate the users by filtering the for the different types of event types  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/a/8a3f89a264cf0f762b6ab1288be240a9391d3e8c.png)
- **Third bucket:** Reveal the MovieID  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/e/0e79ce67f7aab6592355aaeb197b9428066548db.png)

You could also show movie ID using a "top hits" metric aggregation instead of a terms aggregation.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/b/6b7448f3abe91c755044af0337c9ffb5ab0318ea.png)

---

<div class="post-metadata">

### Author: ![ravnica1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravnica1/32/60509_2.png) [@ravnica1](https://discuss.elastic.co/u/ravnica1)
#### Post date: [January 10, 2020, 12:17pm UTC](https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306/3 "2020-01-10T12:17:56Z")

</div>

Thank you Tim for your answer

The business requirements are as outlined in my question, I cannot have email address replicated in the rows. Movie id is not required in the output.

I think I will try to refine the query to aggregate data or use painless query in json input to filter data.

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [January 10, 2020, 5:09pm UTC](https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306/4 "2020-01-10T17:09:09Z")

</div>

> [@ravnica1](#):
>
> ............email ................... added viewed  
> [Jane.Blogs@gmail.com](mailto:Jane.Blogs@gmail.com) ........1 .......... 1

I'm sorry - it wasn't clear what the `1` value is in your example table, and I thought it referred to the movieId.

Is it supposed to be a document count? That wouldn't add up because your example data has a count of `2` for the `Viewed` event types.

---

<div class="post-metadata">

### Author: ![ravnica1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravnica1/32/60509_2.png) [@ravnica1](https://discuss.elastic.co/u/ravnica1)
#### Post date: [January 10, 2020, 5:14pm UTC](https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306/5 "2020-01-10T17:14:20Z")

</div>

Thank you Tim

Yes I can easily get counts, the problem is getting unique count for a specific eventType in the same row of data.

I thought there may be some standard way to accomplish this, I will try with Lucene query and/or painless on json data

---

<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, 2020, 5:14pm UTC](https://discuss.elastic.co/t/unique-filter-in-data-table-visualisation/214306/6 "2020-02-07T17:14:21Z")

</div>

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