Facet term vs Facet label


(David Stendardi) #1

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) #2

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 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/
Twitter : @dadoonet


(David Stendardi) #3

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}

  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 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 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/
Twitter : @dadoonet

--
David Stendardi


(David Stendardi) #4

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

2012/1/12 David Stendardi 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}

  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 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 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/
Twitter : @dadoonet

--
David Stendardi

--
David Stendardi


(chatgris) #5

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 <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}

  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 <javascript:> <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<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/
Twitter : @dadoonet

--
David Stendardi

--
David Stendardi


(system) #6