# Get number of all possible facets (but without producing them)

**URL:** <https://discuss.elastic.co/t/get-number-of-all-possible-facets-but-without-producing-them/9052>\
**Category:** Elasticsearch\
**Created:** [September 18, 2012, 3:04pm UTC](https://discuss.elastic.co/t/get-number-of-all-possible-facets-but-without-producing-them/9052 "2012-09-18T15:04:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pere\_roca\_ristol](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@pere\_roca\_ristol](https://discuss.elastic.co/u/pere_roca_ristol)\
**Post date:** [September 18, 2012, 3:04pm UTC](https://discuss.elastic.co/t/get-number-of-all-possible-facets-but-without-producing-them/9052/1 "2012-09-18T15:04:52Z")

</div>

is there a way to get the "top 10" facets but at the same time get the \*  
count\* of all the possible facets ( count(distinct(kingdom)) in SQL way) we  
could have created (in that case, _all distinct kingdoms_ in our document).

I know I could increase the "size" to a very big number, and count how many  
facets are, only presenting the first 10, but then it generates a very big  
JSON and processing costs may be much bigger.

A simple facet...

"facets" : {  
"kingdom": {  
"terms": {  
"field": "kingdom",  
"size": 10  
}  
}

i mean, i don't want to get something like {term:kingdom1, count:100} for  
each possible facet (kingdom).I just want the first ten 'kingdoms' (the  
more 'popular'), with its name and counts, but get also some info about how  
many possible facets I could have generated.

hope I make me understand, thanks in advance

Pere

--

---

<div class="post-metadata">

**Author:** ![Raffaele\_Sena](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raffaele_sena/32/1759_2.png) [@Raffaele\_Sena](https://discuss.elastic.co/u/Raffaele_Sena)\
**Post date:** [September 18, 2012, 7:23pm UTC](https://discuss.elastic.co/t/get-number-of-all-possible-facets-but-without-producing-them/9052/2 "2012-09-18T19:23:48Z")

</div>

wouldn't the "other" field accomplish what you need ? (or other + 10).  
If I do a search with facets I get my top 10 terms and I guess other  
means there are 1093 more terms that are not showing:

u'facets': {u'wname': {u'\_type': u'terms',  
u'missing': 0,  
u'other': 1093,  
u'terms': [{u'count': 23,  
u'term': u'test\_blueheron'},  
{u'count': 10, u'term': u'PDF'},  
{u'count': 9, u'term': u'MS'},  
{u'count': 6, u'term': u'test'},  
{u'count': 6, u'term': u'image'},  
{u'count': 6, u'term': u'Word'},  
{u'count': 5, u'term': u'OpenOffice'},  
{u'count': 4, u'term': u'with'},  
{u'count': 4, u'term': u'file'},  
{u'count': 4, u'term': u'StarOffice'}],

On Tue, Sep 18, 2012 at 8:04 AM, pere roca ristol [peroc79@gmail.com](mailto:peroc79@gmail.com) wrote:

> is there a way to get the "top 10" facets but at the same time get the count  
> of all the possible facets ( count(distinct(kingdom)) in SQL way) we could  
> have created (in that case, all distinct kingdoms in our document).
> 
> I know I could increase the "size" to a very big number, and count how many  
> facets are, only presenting the first 10, but then it generates a very big  
> JSON and processing costs may be much bigger.
> 
> A simple facet...
> 
> "facets" : {  
> "kingdom": {  
> "terms": {  
> "field": "kingdom",  
> "size": 10  
> }  
> }
> 
> i mean, i don't want to get something like {term:kingdom1, count:100} for  
> each possible facet (kingdom).I just want the first ten 'kingdoms' (the more  
> 'popular'), with its name and counts, but get also some info about how many  
> possible facets I could have generated.
> 
> hope I make me understand, thanks in advance
> 
> Pere
> 
> --

--

---

<div class="post-metadata">

**Author:** ![pere\_roca\_ristol](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@pere\_roca\_ristol](https://discuss.elastic.co/u/pere_roca_ristol)\
**Post date:** [September 19, 2012, 8:28am UTC](https://discuss.elastic.co/t/get-number-of-all-possible-facets-but-without-producing-them/9052/3 "2012-09-19T08:28:12Z")

</div>

nope, as stated here[http://www.elasticsearch.org/guide/reference/api/search/facets/](http://www.elasticsearch.org/guide/reference/api/search/facets/)  
,\* other\* is the number of facet values not included in the returned  
facets.  
if you use 'size':10 in your facet query, it creates 10 'groups', and the  
values (raw data records) not included in these groups are simply summed to  
'other' parameter. So, in your request, you have 1093 records that don't  
fit to your top 10 facets/groups.  
This is not what I need.

On Tuesday, 18 September 2012 21:23:50 UTC+2, Raffaele Sena wrote:

> wouldn't the "other" field accomplish what you need ? (or other + 10).  
> If I do a search with facets I get my top 10 terms and I guess other  
> means there are 1093 more terms that are not showing:
> 
> u'facets': {u'wname': {u'\_type': u'terms',  
> u'missing': 0,  
> u'other': 1093,  
> u'terms': [{u'count': 23,  
> u'term': u'test\_blueheron'},  
> {u'count': 10, u'term': u'PDF'},  
> {u'count': 9, u'term': u'MS'},  
> {u'count': 6, u'term': u'test'},  
> {u'count': 6, u'term': u'image'},  
> {u'count': 6, u'term': u'Word'},  
> {u'count': 5, u'term': u'OpenOffice'},  
> {u'count': 4, u'term': u'with'},  
> {u'count': 4, u'term': u'file'},  
> {u'count': 4, u'term': u'StarOffice'}],
> 
> On Tue, Sep 18, 2012 at 8:04 AM, pere roca ristol \<[per...@gmail.com](mailto:per...@gmail.com)\<javascript:\>\>  
> wrote:
> 
> > is there a way to get the "top 10" facets but at the same time get the  
> > count  
> > of all the possible facets ( count(distinct(kingdom)) in SQL way) we  
> > could  
> > have created (in that case, all distinct kingdoms in our document).
> > 
> > I know I could increase the "size" to a very big number, and count how  
> > many  
> > facets are, only presenting the first 10, but then it generates a very  
> > big  
> > JSON and processing costs may be much bigger.
> > 
> > A simple facet...
> > 
> > "facets" : {  
> > "kingdom": {  
> > "terms": {  
> > "field": "kingdom",  
> > "size": 10  
> > }  
> > }
> > 
> > i mean, i don't want to get something like {term:kingdom1, count:100}  
> > for  
> > each possible facet (kingdom).I just want the first ten 'kingdoms' (the  
> > more  
> > 'popular'), with its name and counts, but get also some info about how  
> > many  
> > possible facets I could have generated.
> > 
> > hope I make me understand, thanks in advance
> > 
> > Pere
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [September 19, 2012, 8:47am UTC](https://discuss.elastic.co/t/get-number-of-all-possible-facets-but-without-producing-them/9052/4 "2012-09-19T08:47:15Z")

</div>

Hi,

you are looking for number of distinct terms in given field, right?  
I am not sure if there is an API for this right now, but you might want to  
look at [GitHub - jprante/elasticsearch-index-termlist: Elasticsearch Index Termlist](https://github.com/jprante/elasticsearch-index-termlist) (it does  
not give you the number but list of terms). However, you could try to talk  
to Jorg if it would be possible to extend this plugin.

Regards,  
Lukas

On Wed, Sep 19, 2012 at 10:28 AM, pere roca ristol [peroc79@gmail.com](mailto:peroc79@gmail.com)wrote:

> nope, as stated here[http://www.elasticsearch.org/guide/reference/api/search/facets/](http://www.elasticsearch.org/guide/reference/api/search/facets/)  
> ,\* other\* is the number of facet values not included in the returned  
> facets.  
> if you use 'size':10 in your facet query, it creates 10 'groups', and  
> the values (raw data records) not included in these groups are simply  
> summed to 'other' parameter. So, in your request, you have 1093 records  
> that don't fit to your top 10 facets/groups.  
> This is not what I need.
> 
> On Tuesday, 18 September 2012 21:23:50 UTC+2, Raffaele Sena wrote:
> 
> > wouldn't the "other" field accomplish what you need ? (or other + 10).  
> > If I do a search with facets I get my top 10 terms and I guess other  
> > means there are 1093 more terms that are not showing:
> > 
> > u'facets': {u'wname': {u'\_type': u'terms',  
> > u'missing': 0,  
> > u'other': 1093,  
> > u'terms': [{u'count': 23,  
> > u'term': u'test\_blueheron'},  
> > {u'count': 10, u'term': u'PDF'},  
> > {u'count': 9, u'term': u'MS'},  
> > {u'count': 6, u'term': u'test'},  
> > {u'count': 6, u'term': u'image'},  
> > {u'count': 6, u'term': u'Word'},  
> > {u'count': 5, u'term': u'OpenOffice'},  
> > {u'count': 4, u'term': u'with'},  
> > {u'count': 4, u'term': u'file'},  
> > {u'count': 4, u'term':  
> > u'StarOffice'}],
> > 
> > On Tue, Sep 18, 2012 at 8:04 AM, pere roca ristol [per...@gmail.com](mailto:per...@gmail.com)  
> > wrote:
> > 
> > > is there a way to get the "top 10" facets but at the same time get the  
> > > count  
> > > of all the possible facets ( count(distinct(kingdom)) in SQL way) we  
> > > could  
> > > have created (in that case, all distinct kingdoms in our document).
> > > 
> > > I know I could increase the "size" to a very big number, and count how  
> > > many  
> > > facets are, only presenting the first 10, but then it generates a very  
> > > big  
> > > JSON and processing costs may be much bigger.
> > > 
> > > A simple facet...
> > > 
> > > "facets" : {  
> > > "kingdom": {  
> > > "terms": {  
> > > "field": "kingdom",  
> > > "size": 10  
> > > }  
> > > }
> > > 
> > > i mean, i don't want to get something like {term:kingdom1, count:100}  
> > > for  
> > > each possible facet (kingdom).I just want the first ten 'kingdoms' (the  
> > > more  
> > > 'popular'), with its name and counts, but get also some info about how  
> > > many  
> > > possible facets I could have generated.
> > > 
> > > hope I make me understand, thanks in advance
> > > 
> > > Pere
> > > 
> > > --
> 
> --

--

---

<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:12am UTC](https://discuss.elastic.co/t/get-number-of-all-possible-facets-but-without-producing-them/9052/5 "2017-07-06T03:12:22Z")

</div>


