# Facet term vs Facet label

**URL:** <https://discuss.elastic.co/t/facet-term-vs-facet-label/6360>\
**Category:** Elasticsearch\
**Created:** [January 12, 2012, 7:55am UTC](https://discuss.elastic.co/t/facet-term-vs-facet-label/6360 "2012-01-12T07:55:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Stendardi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_stendardi/32/2990_2.png) [@David\_Stendardi](https://discuss.elastic.co/u/David_Stendardi)\
**Post date:** [January 12, 2012, 7:55am UTC](https://discuss.elastic.co/t/facet-term-vs-facet-label/6360/1 "2012-01-12T07:55:26Z")

</div>

Hi guys,

Would like to know if someone here share the same need :

When using terms facets, we need a display field different from the  
term that is processed.  
For example with the following document:

{  
categories : [{"id": 1, "label": "foo"}]  
}

Submitting the following query :

{  
facets: { categories: { terms : { field: "categories.id" } } }  
}

We would like to display the following facet results:

foo (1)

One of the solution we found, is to performs a mapping using a  
database query the first time the facet is processed, and then keep  
the result in memory for subsequent displays.

So my question is :  
Is this better to performs this on the index side (maybe by processing  
a term like " foo (1)") but then, how do you achieve I18N  
translations ?

Maybe an label\_field (leveraging the document nature of es) option  
could be helpful when submitting a facet query ?

Example query :

{  
facets: { categories: { terms : { field: "categories.id",  
label\_field: "categories.label" } } }  
}

Would returns something like :

{  
term: 1  
count: 1  
label: "foo"  
[...]  
}

Cheers

--  
David Stendardi

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 12, 2012, 8:00am UTC](https://discuss.elastic.co/t/facet-term-vs-facet-label/6360/2 "2012-01-12T08:00:17Z")

</div>

Hi David,

I did not understand your use case.  
Why don't you make your facet directly on categories.label ?  
{  
facets: { categories: { terms : { field: "categories.label" } } }  
}

It should give you the results you are waiting for, should'nt it ?

David.

Le 12 janvier 2012 à 08:55, David Stendardi [david.stendardi@gmail.com](mailto:david.stendardi@gmail.com) a  
écrit :

> Hi guys,
> 
> Would like to know if someone here share the same need :
> 
> When using terms facets, we need a display field different from the  
> term that is processed.  
> For example with the following document:
> 
> {  
> categories : [{"id": 1, "label": "foo"}]  
> }
> 
> Submitting the following query :
> 
> {  
> facets: { categories: { terms : { field: "categories.id" } } }  
> }
> 
> We would like to display the following facet results:
> 
> foo (1)
> 
> One of the solution we found, is to performs a mapping using a  
> database query the first time the facet is processed, and then keep  
> the result in memory for subsequent displays.
> 
> So my question is :  
> Is this better to performs this on the index side (maybe by processing  
> a term like " foo (1)") but then, how do you achieve I18N  
> translations ?
> 
> Maybe an label\_field (leveraging the document nature of es) option  
> could be helpful when submitting a facet query ?
> 
> Example query :
> 
> {  
> facets: { categories: { terms : { field: "categories.id",  
> label\_field: "categories.label" } } }  
> }
> 
> Would returns something like :
> 
> {  
> term: 1  
> count: 1  
> label: "foo"  
> [...]  
> }
> 
> Cheers
> 
> --  
> David Stendardi  
> --  
> David Pilato  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![David\_Stendardi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_stendardi/32/2990_2.png) [@David\_Stendardi](https://discuss.elastic.co/u/David_Stendardi)\
**Post date:** [January 12, 2012, 9:25am UTC](https://discuss.elastic.co/t/facet-term-vs-facet-label/6360/3 "2012-01-12T09:25:41Z")

</div>

Thank you for your interest David,

Here are some (valid ?) use cases for that :

1. duplicate labels :

- you may have the same same label for two criteria (yeah i know this is weird)  
Currently we have a tree of categories which contains same labels in  
different parts of the tree :

ex (our tree is a bit more "leafy") :

foo  
-\>bar  
abc  
-\>bar

I guess we can solve this problem by indexing a path of labels, and  
just retrieve the last part in the view (

ex : "foo \> bar".split(" \> ").pop() )

1. Url vs labels

You may want to process url fields, instead of labels, and then just  
process your view like this :

[{term.label}](https://discuss.elastic.co/search/{term.id})

1. I18N

You may want also use a different field base on user culture :

considering the doc :

{  
categories: [{ id: 1, "labels": {"fr": "bonjour", "en": "Hello"} }]  
}

then you can customize your facet query using the current locale :

{  
facets: { categories: { terms : { field: "categories.id",  
label\_field: "categories.labels.{locale}" } } }  
}

2012/1/12 [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr):

> Hi David,
> 
> I did not understand your use case.
> 
> Why don't you make your facet directly on categories.label ?
> 
> {  
> facets: { categories: { terms : { field: "categories.label" } } }  
> }
> 
> It should give you the results you are waiting for, should'nt it ?
> 
> David.
> 
> Le 12 janvier 2012 à 08:55, David Stendardi [david.stendardi@gmail.com](mailto:david.stendardi@gmail.com) a  
> écrit :
> 
> > Hi guys,
> > 
> > Would like to know if someone here share the same need :
> > 
> > When using terms facets, we need a display field different from the  
> > term that is processed.  
> > For example with the following document:
> > 
> > {  
> > categories : [{"id": 1, "label": "foo"}]  
> > }
> > 
> > Submitting the following query :
> > 
> > {  
> > facets: { categories: { terms : { field: "categories.id" } } }  
> > }
> > 
> > We would like to display the following facet results:
> > 
> > foo (1)
> > 
> > One of the solution we found, is to performs a mapping using a  
> > database query the first time the facet is processed, and then keep  
> > the result in memory for subsequent displays.
> > 
> > So my question is :  
> > Is this better to performs this on the index side (maybe by processing  
> > a term like " foo (1)") but then, how do you achieve I18N  
> > translations ?
> > 
> > Maybe an label\_field (leveraging the document nature of es) option  
> > could be helpful when submitting a facet query ?
> > 
> > Example query :
> > 
> > {  
> > facets: { categories: { terms : { field: "categories.id",  
> > label\_field: "categories.label" } } }  
> > }
> > 
> > Would returns something like :
> > 
> > {  
> > term: 1  
> > count: 1  
> > label: "foo"  
> > [...]  
> > }
> > 
> > Cheers
> > 
> > --  
> > David Stendardi
> 
> --  
> David Pilato  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet

--  
David Stendardi

---

<div class="post-metadata">

**Author:** ![David\_Stendardi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_stendardi/32/2990_2.png) [@David\_Stendardi](https://discuss.elastic.co/u/David_Stendardi)\
**Post date:** [January 12, 2012, 10:59am UTC](https://discuss.elastic.co/t/facet-term-vs-facet-label/6360/4 "2012-01-12T10:59:29Z")

</div>

The last one (i18n) might be solved by using one index per locale.

2012/1/12 David Stendardi [david.stendardi@gmail.com](mailto:david.stendardi@gmail.com):

> Thank you for your interest David,
> 
> Here are some (valid ?) use cases for that :
> 
> 1. duplicate labels :
> 
> - you may have the same same label for two criteria (yeah i know this is weird)  
> Currently we have a tree of categories which contains same labels in  
> different parts of the tree :
> 
> ex (our tree is a bit more "leafy") :
> 
> foo  
> -\>bar  
> abc  
> -\>bar
> 
> I guess we can solve this problem by indexing a path of labels, and  
> just retrieve the last part in the view (
> 
> ex : "foo \> bar".split(" \> ").pop() )
> 
> 1. Url vs labels
> 
> You may want to process url fields, instead of labels, and then just  
> process your view like this :
> 
> [{term.label}](https://discuss.elastic.co/search/{term.id})
> 
> 1. I18N
> 
> You may want also use a different field base on user culture :
> 
> considering the doc :
> 
> {  
> categories: [{ id: 1, "labels": {"fr": "bonjour", "en": "Hello"} }]  
> }
> 
> then you can customize your facet query using the current locale :
> 
> {  
> facets: { categories: { terms : { field: "categories.id",  
> label\_field: "categories.labels.{locale}" } } }  
> }
> 
> 2012/1/12 [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr):
> 
> > Hi David,
> > 
> > I did not understand your use case.
> > 
> > Why don't you make your facet directly on categories.label ?
> > 
> > {  
> > facets: { categories: { terms : { field: "categories.label" } } }  
> > }
> > 
> > It should give you the results you are waiting for, should'nt it ?
> > 
> > David.
> > 
> > Le 12 janvier 2012 à 08:55, David Stendardi [david.stendardi@gmail.com](mailto:david.stendardi@gmail.com) a  
> > écrit :
> > 
> > > Hi guys,
> > > 
> > > Would like to know if someone here share the same need :
> > > 
> > > When using terms facets, we need a display field different from the  
> > > term that is processed.  
> > > For example with the following document:
> > > 
> > > {  
> > > categories : [{"id": 1, "label": "foo"}]  
> > > }
> > > 
> > > Submitting the following query :
> > > 
> > > {  
> > > facets: { categories: { terms : { field: "categories.id" } } }  
> > > }
> > > 
> > > We would like to display the following facet results:
> > > 
> > > foo (1)
> > > 
> > > One of the solution we found, is to performs a mapping using a  
> > > database query the first time the facet is processed, and then keep  
> > > the result in memory for subsequent displays.
> > > 
> > > So my question is :  
> > > Is this better to performs this on the index side (maybe by processing  
> > > a term like " foo (1)") but then, how do you achieve I18N  
> > > translations ?
> > > 
> > > Maybe an label\_field (leveraging the document nature of es) option  
> > > could be helpful when submitting a facet query ?
> > > 
> > > Example query :
> > > 
> > > {  
> > > facets: { categories: { terms : { field: "categories.id",  
> > > label\_field: "categories.label" } } }  
> > > }
> > > 
> > > Would returns something like :
> > > 
> > > {  
> > > term: 1  
> > > count: 1  
> > > label: "foo"  
> > > [...]  
> > > }
> > > 
> > > Cheers
> > > 
> > > --  
> > > David Stendardi
> > 
> > --  
> > David Pilato  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet
> 
> --  
> David Stendardi

--  
David Stendardi

---

<div class="post-metadata">

**Author:** ![chatgris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatgris/32/2773_2.png) [@chatgris](https://discuss.elastic.co/u/chatgris)\
**Post date:** [August 10, 2012, 1:54pm UTC](https://discuss.elastic.co/t/facet-term-vs-facet-label/6360/5 "2012-08-10T13:54:42Z")

</div>

Hello,

Did you find a solution to handle duplicate labels ?

On Thursday, January 12, 2012 11:59:29 AM UTC+1, david.stendardi wrote:

> The last one (i18n) might be solved by using one index per locale.
> 
> 2012/1/12 David Stendardi \<[david.s...@gmail.com](mailto:david.s...@gmail.com) \<javascript:\>\>:
> 
> > Thank you for your interest David,
> > 
> > Here are some (valid ?) use cases for that :
> > 
> > 1. duplicate labels :
> > 
> > - you may have the same same label for two criteria (yeah i know this is  
> > weird)  
> > Currently we have a tree of categories which contains same labels in  
> > different parts of the tree :
> > 
> > ex (our tree is a bit more "leafy") :
> > 
> > foo  
> > -\>bar  
> > abc  
> > -\>bar
> > 
> > I guess we can solve this problem by indexing a path of labels, and  
> > just retrieve the last part in the view (
> > 
> > ex : "foo \> bar".split(" \> ").pop() )
> > 
> > 1. Url vs labels
> > 
> > You may want to process url fields, instead of labels, and then just  
> > process your view like this :
> > 
> > [{term.label}](https://discuss.elastic.co/search/{term.id})
> > 
> > 1. I18N
> > 
> > You may want also use a different field base on user culture :
> > 
> > considering the doc :
> > 
> > {  
> > categories: [{ id: 1, "labels": {"fr": "bonjour", "en": "Hello"} }]  
> > }
> > 
> > then you can customize your facet query using the current locale :
> > 
> > {  
> > facets: { categories: { terms : { field: "categories.id",  
> > label\_field: "categories.labels.{locale}" } } }  
> > }
> > 
> > 2012/1/12 [da...@pilato.fr](mailto:da...@pilato.fr) \<javascript:\> \<[da...@pilato.fr](mailto:da...@pilato.fr) \<javascript:\>\>:
> > 
> > > Hi David,
> > > 
> > > I did not understand your use case.
> > > 
> > > Why don't you make your facet directly on categories.label ?
> > > 
> > > {  
> > > facets: { categories: { terms : { field: "categories.label" } } }  
> > > }
> > > 
> > > It should give you the results you are waiting for, should'nt it ?
> > > 
> > > David.
> > > 
> > > Le 12 janvier 2012 à 08:55, David Stendardi \<[david.s...@gmail.com](mailto:david.s...@gmail.com)\<javascript:\>\>  
> > > a  
> > > écrit :
> > > 
> > > > Hi guys,
> > > > 
> > > > Would like to know if someone here share the same need :
> > > > 
> > > > When using terms facets, we need a display field different from the  
> > > > term that is processed.  
> > > > For example with the following document:
> > > > 
> > > > {  
> > > > categories : [{"id": 1, "label": "foo"}]  
> > > > }
> > > > 
> > > > Submitting the following query :
> > > > 
> > > > {  
> > > > facets: { categories: { terms : { field: "categories.id" } } }  
> > > > }
> > > > 
> > > > We would like to display the following facet results:
> > > > 
> > > > foo (1)
> > > > 
> > > > One of the solution we found, is to performs a mapping using a  
> > > > database query the first time the facet is processed, and then keep  
> > > > the result in memory for subsequent displays.
> > > > 
> > > > So my question is :  
> > > > Is this better to performs this on the index side (maybe by processing  
> > > > a term like " foo (1)") but then, how do you achieve I18N  
> > > > translations ?
> > > > 
> > > > Maybe an label\_field (leveraging the document nature of es) option  
> > > > could be helpful when submitting a facet query ?
> > > > 
> > > > Example query :
> > > > 
> > > > {  
> > > > facets: { categories: { terms : { field: "categories.id",  
> > > > label\_field: "categories.label" } } }  
> > > > }
> > > > 
> > > > Would returns something like :
> > > > 
> > > > {  
> > > > term: 1  
> > > > count: 1  
> > > > label: "foo"  
> > > > [...]  
> > > > }
> > > > 
> > > > Cheers
> > > > 
> > > > --  
> > > > David Stendardi
> > > 
> > > --  
> > > David Pilato  
> > > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > > Twitter : @dadoonet
> > 
> > --  
> > David Stendardi
> 
> --  
> David Stendardi

---

<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:16am UTC](https://discuss.elastic.co/t/facet-term-vs-facet-label/6360/6 "2017-07-06T03:16:49Z")

</div>


