# Unique count exact value

**URL:** <https://discuss.elastic.co/t/unique-count-exact-value/272910>\
**Category:** Elasticsearch\
**Created:** [May 13, 2021, 12:50pm UTC](https://discuss.elastic.co/t/unique-count-exact-value/272910 "2021-05-13T12:50:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)\
**Post date:** [May 13, 2021, 12:50pm UTC](https://discuss.elastic.co/t/unique-count-exact-value/272910/1 "2021-05-13T12:50:47Z")

</div>

hi ,  
we trying to use unique count in Elasticsearch  
we know its Cardinality Aggregation and give approximate count .  
we also tried using "precision\_threshold":10000 , but still count is not exact.

let me give info -  
index contain total 5000 record for 1 month period  
distinct record -4234  
have data like this -

> outlet-day,swat\_code  
> 5102~011~007~00053307-2021-04-25 ,100006  
> 5102~020~001~00053384-2021-04-27 ,100006  
> 5102~020~010~00053292-2021-04-27 ,100006  
> 5102~030~006~00052924-2021-04-29 ,100014  
> 5102~040~003~00053106-2021-04-27 ,100006  
> 5102~040~006~00218477-2021-04-28 ,100006  
> 5102~040~013~00053208-2021-04-29 ,100006  
> 5102~050~009~00218320-2021-04-28 ,100014  
> 5103~010~001~01019629-2021-04-25 ,100007  
> 5103~010~001~01029465-2021-04-25 ,100013  
> 5103~040~013~01141795-2021-04-27 ,100005  
> 5104~010~005~01025316-2021-04-26 ,100015  
> 5104~020~007~00047242-2021-04-27 ,100015  
> 5104~020~007~00647900-2021-04-27 ,100015  
> 5104~030~009~00047794-2021-04-25 ,100015  
> 5105~020~004~01141214-2021-04-29 ,100002  
> 5105~030~008~00059677-2021-04-29 ,100002  
> 5105~030~010~00060227-2021-04-29 ,100002  
> 5105~040~006~00960571-2021-04-29 ,100002  
> 5106~020~005~00929656-2021-04-29 ,100015  
> 5106~030~006~00059961-2021-04-29 ,100015  
> 5107~010~003~00218474-2021-04-26 ,100002  
> 5107~040~005~00457483-2021-04-25 ,100002

my first query -

> {  
> "aggs": {  
> "1": {  
> "cardinality": {  
> "field": "outlet-day.keyword",  
> "precision\_threshold": 10000  
> }  
> }  
> },

even after precision is not give exact count .

my other query for same date range -  
i added extra term aggregation -

> {  
> "aggs": {  
> "2": {  
> "terms": {  
> "field": "swat\_code.keyword",  
> "order": {  
> "1": "desc"  
> },  
> "size": 5  
> },  
> "aggs": {  
> "1": {  
> "cardinality": {  
> "field": "outlet-day.keyword"  
> }  
> }  
> }  
> }  
> }

this give current count even without precision\_threshold.  
but for matric visual , how we can get exact count .

Please let us know if there is any other way .

Thanks in advance .

Dilip

---

<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 10, 2021, 12:51pm UTC](https://discuss.elastic.co/t/unique-count-exact-value/272910/2 "2021-06-10T12:51:13Z")

</div>

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