# Get total of distinct values in a field

**URL:** <https://discuss.elastic.co/t/get-total-of-distinct-values-in-a-field/16092>\
**Category:** Elasticsearch\
**Created:** [March 3, 2014, 12:16am UTC](https://discuss.elastic.co/t/get-total-of-distinct-values-in-a-field/16092 "2014-03-03T00:16:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Luis\_Betancour](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jorge\_Luis\_Betancour](https://discuss.elastic.co/u/Jorge_Luis_Betancour)\
**Post date:** [March 3, 2014, 12:16am UTC](https://discuss.elastic.co/t/get-total-of-distinct-values-in-a-field/16092/1 "2014-03-03T00:16:26Z")

</div>

Hi:

I'm indexing a lot of information from twitter and other social media, is there a way I can get a count of all the distinct terms present in a field ? I've seen something mentioned/closed on [https://github.com/elasticsearch/elasticsearch/issues/1044](https://github.com/elasticsearch/elasticsearch/issues/1044). But even with the new aggregation framework I see how this would be possible, in this particular case I'm trying to get the total number of authors (which could go very high), I know that by using the facet terms I could all count of all author, but I'm interested only in the total.

Greetings,

* * *

III Escuela Internacional de Invierno en la UCI del 17 al 28 de febrero del 2014. Ver www.uci.cu

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/509052727.11780359.1393805786037.JavaMail.zimbra%40uci.cu](https://groups.google.com/d/msgid/elasticsearch/509052727.11780359.1393805786037.JavaMail.zimbra%40uci.cu).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Dan\_Fairs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_fairs/32/1205_2.png) [@Dan\_Fairs](https://discuss.elastic.co/u/Dan_Fairs)\
**Post date:** [March 3, 2014, 9:33pm UTC](https://discuss.elastic.co/t/get-total-of-distinct-values-in-a-field/16092/2 "2014-03-03T21:33:59Z")

</div>

> I'm indexing a lot of information from twitter and other social media, is there a way I can get a count of all the distinct terms present in a field ? I've seen something mentioned/closed on [Terms facet: count and from features · Issue #1044 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1044). But even with the new aggregation framework I see how this would be possible, in this particular case I'm trying to get the total number of authors (which could go very high), I know that by using the facet terms I could all count of all author, but I'm interested only in the total.

It's not ideal, but we do this by creating a term facet on the field in question, and counting the number of entries.

I'd also note that we don't do this in live web requests, but in batch jobs, and store the result!

## Cheers, Dan

Dan Fairs | [dan.fairs@gmail.com](mailto:dan.fairs@gmail.com) | @danfairs | [secondsync.com](http://secondsync.com)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/C08902A7-958D-4804-8023-F57E4950EFBB%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/C08902A7-958D-4804-8023-F57E4950EFBB%40gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jorge\_Luis\_Betancour](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jorge\_Luis\_Betancour](https://discuss.elastic.co/u/Jorge_Luis_Betancour)\
**Post date:** [March 3, 2014, 10:26pm UTC](https://discuss.elastic.co/t/get-total-of-distinct-values-in-a-field/16092/3 "2014-03-03T22:26:49Z")

</div>

Thanks for the reply! Yeap I think this is the only workaround. Now I'm wondering if is possible to cache this value using the elasticsearch builtin cache, because on my case I needed for live requests, but I don't mind if there are a few seconds of stolen data.

----- Original Message -----

From: "Dan Fairs" [dan.fairs@gmail.com](mailto:dan.fairs@gmail.com)  
To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Sent: Monday, March 3, 2014 4:33:59 PM  
Subject: Re: Get total of distinct values in a field

I'm indexing a lot of information from twitter and other social media, is there a way I can get a count of all the distinct terms present in a field ? I've seen something mentioned/closed on [https://github.com/elasticsearch/elasticsearch/issues/1044](https://github.com/elasticsearch/elasticsearch/issues/1044) . But even with the new aggregation framework I see how this would be possible, in this particular case I'm trying to get the total number of authors (which could go very high), I know that by using the facet terms I could all count of all author, but I'm interested only in the total.

It's not ideal, but we do this by creating a term facet on the field in question, and counting the number of entries.

I'd also note that we don't do this in live web requests, but in batch jobs, and store the result!

## Cheers, Dan

Dan Fairs | [dan.fairs@gmail.com](mailto:dan.fairs@gmail.com) | @danfairs | [secondsync.com](http://secondsync.com)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/C08902A7-958D-4804-8023-F57E4950EFBB%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/C08902A7-958D-4804-8023-F57E4950EFBB%40gmail.com) .  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out) .

* * *

III Escuela Internacional de Invierno en la UCI del 17 al 28 de febrero del 2014. Ver www.uci.cu

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/27774731.12054375.1393885609260.JavaMail.zimbra%40uci.cu](https://groups.google.com/d/msgid/elasticsearch/27774731.12054375.1393885609260.JavaMail.zimbra%40uci.cu).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:45am UTC](https://discuss.elastic.co/t/get-total-of-distinct-values-in-a-field/16092/4 "2017-07-06T01:45:59Z")

</div>


