# Getting the number of unique facet values

**URL:** <https://discuss.elastic.co/t/getting-the-number-of-unique-facet-values/7135>\
**Category:** Elasticsearch\
**Created:** [March 26, 2012, 9:29pm UTC](https://discuss.elastic.co/t/getting-the-number-of-unique-facet-values/7135 "2012-03-26T21:29:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zmicier](https://avatars.discourse-cdn.com/v4/letter/z/ecc23a/32.png) [@Zmicier](https://discuss.elastic.co/u/Zmicier)\
**Post date:** [March 26, 2012, 9:29pm UTC](https://discuss.elastic.co/t/getting-the-number-of-unique-facet-values/7135/1 "2012-03-26T21:29:01Z")

</div>

Is it possible to get the total number of unique facet values without  
getting all of them?

For example, there may be thousands of unique facet values for a  
particular facet, and while I am getting only top 10 facet values  
with counts, I also want to know how many of the unique facet values  
remain (for example, for pagination).

Note that this is different from the total facet count currently  
returned. As far as I understand, the information should be available  
internally. It would be great be able to get it out of the system.

Thank you

Dmitry

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 27, 2012, 6:56pm UTC](https://discuss.elastic.co/t/getting-the-number-of-unique-facet-values/7135/2 "2012-03-27T18:56:31Z")

</div>

This one is tricky, because we do a "scatter gather" type computation of  
the terms facet. We could potentially get a unique number per shard, and  
then the result would be an approximation.

On Mon, Mar 26, 2012 at 11:29 PM, Zmicier [zialonka@gmail.com](mailto:zialonka@gmail.com) wrote:

> Is it possible to get the total number of unique facet values without  
> getting all of them?
> 
> For example, there may be thousands of unique facet values for a  
> particular facet, and while I am getting only top 10 facet values  
> with counts, I also want to know how many of the unique facet values  
> remain (for example, for pagination).
> 
> Note that this is different from the total facet count currently  
> returned. As far as I understand, the information should be available  
> internally. It would be great be able to get it out of the system.
> 
> Thank you
> 
> Dmitry

---

<div class="post-metadata">

**Author:** ![Zmicier](https://avatars.discourse-cdn.com/v4/letter/z/ecc23a/32.png) [@Zmicier](https://discuss.elastic.co/u/Zmicier)\
**Post date:** [April 17, 2012, 5:37pm UTC](https://discuss.elastic.co/t/getting-the-number-of-unique-facet-values/7135/3 "2012-04-17T17:37:47Z")

</div>

Yes, I realized that it is much more difficult to do it in a  
distributed system. In my system, data follows a power-law  
distribution, so I used the facet statistics that elastic currently  
gives me (top N counts, total count, and other count) to fit the  
distribution and use it to estimate approximate unique count, which  
does a reasonable job.

On Mar 27, 2:56 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> This one is tricky, because we do a "scatter gather" type computation of  
> the terms facet. We could potentially get a unique number per shard, and  
> then the result would be an approximation.
> 
> On Mon, Mar 26, 2012 at 11:29 PM, Zmicier [zialo...@gmail.com](mailto:zialo...@gmail.com) wrote:
> 
> > Is it possible to get the total number of unique facet values without  
> > getting all of them?
> 
> > For example, there may be thousands of unique facet values for a  
> > particular facet, and while I am getting only top 10 facet values  
> > with counts, I also want to know how many of the unique facet values  
> > remain (for example, for pagination).
> 
> > Note that this is different from the total facet count currently  
> > returned. As far as I understand, the information should be available  
> > internally. It would be great be able to get it out of the system.
> 
> > Thank you
> 
> > Dmitry

---

<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, 3:32am UTC](https://discuss.elastic.co/t/getting-the-number-of-unique-facet-values/7135/4 "2017-07-06T03:32:10Z")

</div>


