# Terms facet on a single type

**URL:** https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376
**Category:** Elasticsearch
**Created:** [June 12, 2013, 9:40am UTC](https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376 "2013-06-12T09:40:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Mehrez\_Marouani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehrez_marouani/32/1218_2.png) [@Mehrez\_Marouani](https://discuss.elastic.co/u/Mehrez_Marouani)
#### Post date: [June 12, 2013, 9:40am UTC](https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376/1 "2013-06-12T09:40:02Z")

</div>

Hi all.

Is it possible to have "type wide" term facets with [all\_terms: true] ?  
I have 2 types in the same index but when I request a terms facet with  
all\_terms=true, it returns the terms in the 2 types.  
I already tried with a facet filter (see the exemple below) but it was the  
same.

{  
"query" : {  
"match\_all" : { }  
},  
"size":0,  
"facets" : {  
"ENGINE\_FACET" : {  
"terms" : {  
"field" : "engine",  
"size" : 10,  
"order" : "term",  
"all\_terms" : true  
},  
"facet\_filter" : {  
"type" : {  
"value" : "vehicle1"  
}  
}  
}  
}  
}

Regards,

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Mehrez\_Marouani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehrez_marouani/32/1218_2.png) [@Mehrez\_Marouani](https://discuss.elastic.co/u/Mehrez_Marouani)
#### Post date: [June 12, 2013, 9:46am UTC](https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376/2 "2013-06-12T09:46:20Z")

</div>

FYI

Tried with ES version 0.20.6.

On Wednesday, June 12, 2013 11:40:02 AM UTC+2, Mehrez Marouani wrote:

> Hi all.
> 
> Is it possible to have "type wide" term facets with [all\_terms: true] ?  
> I have 2 types in the same index but when I request a terms facet with  
> all\_terms=true, it returns the terms in the 2 types.  
> I already tried with a facet filter (see the exemple below) but it was the  
> same.
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "size":0,  
> "facets" : {  
> "ENGINE\_FACET" : {  
> "terms" : {  
> "field" : "engine",  
> "size" : 10,  
> "order" : "term",  
> "all\_terms" : true  
> },  
> "facet\_filter" : {  
> "type" : {  
> "value" : "vehicle1"  
> }  
> }  
> }  
> }  
> }
> 
> Regards,

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Mehrez\_Marouani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehrez_marouani/32/1218_2.png) [@Mehrez\_Marouani](https://discuss.elastic.co/u/Mehrez_Marouani)
#### Post date: [June 12, 2013, 11:06am UTC](https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376/3 "2013-06-12T11:06:21Z")

</div>

UP

On Wednesday, June 12, 2013 11:40:02 AM UTC+2, Mehrez Marouani wrote:

> Hi all.
> 
> Is it possible to have "type wide" term facets with [all\_terms: true] ?  
> I have 2 types in the same index but when I request a terms facet with  
> all\_terms=true, it returns the terms in the 2 types.  
> I already tried with a facet filter (see the exemple below) but it was the  
> same.
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "size":0,  
> "facets" : {  
> "ENGINE\_FACET" : {  
> "terms" : {  
> "field" : "engine",  
> "size" : 10,  
> "order" : "term",  
> "all\_terms" : true  
> },  
> "facet\_filter" : {  
> "type" : {  
> "value" : "vehicle1"  
> }  
> }  
> }  
> }  
> }
> 
> Regards,

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)
#### Post date: [June 12, 2013, 12:12pm UTC](https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376/4 "2013-06-12T12:12:02Z")

</div>

Hi Mehrez,

The all\_terms setting indicate whether you want to terms which have had 0  
count in the result to be filtered out (all\_terms=false) or returned as  
well (all\_terms=true). Since facets always work with all the terms in the  
index, you will may always get terms that belong to all types if you use  
all\_terms=true. The facet filter works by limiting the documents that are  
considered for this facet so all terms of non-vehicle1 types remain on  
count 0 but are still returned.

If you want complete separation between types, you might considering using  
an index per vehicle type. You can still search all them using an alias if  
you need to, or search only one & facet with all\_terms=true and get what  
you want.

Cheers,  
Boaz

On Wednesday, June 12, 2013 11:40:02 AM UTC+2, Mehrez Marouani wrote:

> Hi all.
> 
> Is it possible to have "type wide" term facets with [all\_terms: true] ?  
> I have 2 types in the same index but when I request a terms facet with  
> all\_terms=true, it returns the terms in the 2 types.  
> I already tried with a facet filter (see the exemple below) but it was the  
> same.
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "size":0,  
> "facets" : {  
> "ENGINE\_FACET" : {  
> "terms" : {  
> "field" : "engine",  
> "size" : 10,  
> "order" : "term",  
> "all\_terms" : true  
> },  
> "facet\_filter" : {  
> "type" : {  
> "value" : "vehicle1"  
> }  
> }  
> }  
> }  
> }
> 
> Regards,

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Mehrez\_Marouani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehrez_marouani/32/1218_2.png) [@Mehrez\_Marouani](https://discuss.elastic.co/u/Mehrez_Marouani)
#### Post date: [June 12, 2013, 3:44pm UTC](https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376/5 "2013-06-12T15:44:19Z")

</div>

Thanks Boaz for your clarification.

I fixed it by indexing the property under a different name in each type 🙂

Regards,

On Wednesday, June 12, 2013 2:12:02 PM UTC+2, Boaz Leskes wrote:

> Hi Mehrez,
> 
> The all\_terms setting indicate whether you want to terms which have had 0  
> count in the result to be filtered out (all\_terms=false) or returned as  
> well (all\_terms=true). Since facets always work with all the terms in the  
> index, you will may always get terms that belong to all types if you use  
> all\_terms=true. The facet filter works by limiting the documents that are  
> considered for this facet so all terms of non-vehicle1 types remain on  
> count 0 but are still returned.
> 
> If you want complete separation between types, you might considering using  
> an index per vehicle type. You can still search all them using an alias if  
> you need to, or search only one & facet with all\_terms=true and get what  
> you want.
> 
> Cheers,  
> Boaz
> 
> On Wednesday, June 12, 2013 11:40:02 AM UTC+2, Mehrez Marouani wrote:
> 
> > Hi all.
> > 
> > Is it possible to have "type wide" term facets with [all\_terms: true] ?  
> > I have 2 types in the same index but when I request a terms facet with  
> > all\_terms=true, it returns the terms in the 2 types.  
> > I already tried with a facet filter (see the exemple below) but it was  
> > the same.
> > 
> > {  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "size":0,  
> > "facets" : {  
> > "ENGINE\_FACET" : {  
> > "terms" : {  
> > "field" : "engine",  
> > "size" : 10,  
> > "order" : "term",  
> > "all\_terms" : true  
> > },  
> > "facet\_filter" : {  
> > "type" : {  
> > "value" : "vehicle1"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > Regards,

--  
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).  
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, 2:31am UTC](https://discuss.elastic.co/t/terms-facet-on-a-single-type/12376/6 "2017-07-06T02:31:33Z")

</div>


