# TimeLion cardinality with filter

**URL:** <https://discuss.elastic.co/t/timelion-cardinality-with-filter/47774>\
**Category:** Kibana\
**Tags:** timelion\
**Created:** [April 19, 2016, 10:29am UTC](https://discuss.elastic.co/t/timelion-cardinality-with-filter/47774 "2016-04-19T10:29:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [April 19, 2016, 10:29am UTC](https://discuss.elastic.co/t/timelion-cardinality-with-filter/47774/1 "2016-04-19T10:29:47Z")

</div>

Hi, I need to provide a unqiue count of userId for a given referer domain.

I tried:  
.es('refererDomain:instyle.com AND metric:cardinality=userId.raw')

But it returns zero results. How do I do this? Many thanks.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [April 26, 2016, 7:51am UTC](https://discuss.elastic.co/t/timelion-cardinality-with-filter/47774/2 "2016-04-26T07:51:58Z")

</div>

There is no TimeLion tag so please pass this on to @rashidkpc many thanks...

@bhatch perhaps you know?

---

<div class="post-metadata">

**Author:** ![bhatch](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@bhatch](https://discuss.elastic.co/u/bhatch)\
**Post date:** [April 26, 2016, 3:52pm UTC](https://discuss.elastic.co/t/timelion-cardinality-with-filter/47774/3 "2016-04-26T15:52:35Z")

</div>

Here is the list of options for .es(). Each option is separated by a comma.

 ![](https://us1.discourse-cdn.com/elastic/original/2X/b/b50e56ef187fefc44542cb611ed813d2d2c5a133.png)

Try using this format. We have to separate the query from the metric.

`.es(q='refererDomain:instyle.com', metric='cardinality=userId.raw')`

This kind of query could be done in Kibana itself though. Where TimeLion gets cool is how you can divide the results of two queries. That is something you can't do in Kibana.

`.es(q='refererDomain:instyle.com',metric='cardinality=userId.raw').divide(.es(metric='cardinality=userId.raw')).multiply(100).label('instyle.com').title('Percent of users who visited instyle.com')`

(I think I got the syntax right, haven't tested it). Now we are taking the unique count of users who have a domain of [instyle.com](http://instyle.com), and dividing it by the total unique count of users. We then multiply that by 100 to get a nice round number and then add a label and title to the graph. You can effectively chain things together forever.

Here is a list of all of the functions.

> <https://github.com/elastic/timelion/blob/master/FUNCTIONS.md>

---

<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:** [July 6, 2017, 1:55pm UTC](https://discuss.elastic.co/t/timelion-cardinality-with-filter/47774/4 "2017-07-06T13:55:03Z")

</div>


