# Unique count on a term more than documents? Is that possible?

**URL:** <https://discuss.elastic.co/t/unique-count-on-a-term-more-than-documents-is-that-possible/132497>\
**Category:** Elasticsearch\
**Created:** [May 18, 2018, 1:55pm UTC](https://discuss.elastic.co/t/unique-count-on-a-term-more-than-documents-is-that-possible/132497 "2018-05-18T13:55:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkaramol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkaramol/32/22610_2.png) [@pkaramol](https://discuss.elastic.co/u/pkaramol)\
**Post date:** [May 18, 2018, 1:55pm UTC](https://discuss.elastic.co/t/unique-count-on-a-term-more-than-documents-is-that-possible/132497/1 "2018-05-18T13:55:02Z")

</div>

How is the following possible when searching in an index pattern?  
How can the unique appearances of a `keyword` term be more than the documents themselves?

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

---

<div class="post-metadata">

**Author:** ![Johnnycc1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnnycc1/32/26069_2.png) [@Johnnycc1](https://discuss.elastic.co/u/Johnnycc1)\
**Post date:** [May 19, 2018, 4:31am UTC](https://discuss.elastic.co/t/unique-count-on-a-term-more-than-documents-is-that-possible/132497/2 "2018-05-19T04:31:51Z")

</div>

"Unique count" in kibana uses the cardinality aggregation --\> see here  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html)

If you read the cardinality aggregation page you will see its an approximate unique count. So short answer is due to the distributed nature of elasticsearch - unique counts can only be approximates (unless your index only has a single shard).

---

<div class="post-metadata">

**Author:** ![pkaramol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkaramol/32/22610_2.png) [@pkaramol](https://discuss.elastic.co/u/pkaramol)\
**Post date:** [May 21, 2018, 8:08am UTC](https://discuss.elastic.co/t/unique-count-on-a-term-more-than-documents-is-that-possible/132497/3 "2018-05-21T08:08:13Z")

</div>

Thx for this clarification;  
so is there a way (or what is the recommended way) to make this comparison:

**exact** number of unique entries (based on some field)

vs

**exact** number of **all** documents

?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 21, 2018, 8:12am UTC](https://discuss.elastic.co/t/unique-count-on-a-term-more-than-documents-is-that-possible/132497/4 "2018-05-21T08:12:48Z")

</div>

Document count is not approximated, so will be accurate. The cardinality aggregation can be exact as long as you have all your data in a single shard. For a discussion on why this is not possible in Elasticsearch as you scale out, have a look at [this thread](https://discuss.elastic.co/t/aggregation-with-terms-and-cardinality-deliver-different-results/131155/2).

---

<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:** [June 18, 2018, 8:24am UTC](https://discuss.elastic.co/t/unique-count-on-a-term-more-than-documents-is-that-possible/132497/5 "2018-06-18T08:24:11Z")

</div>

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