How does facets work

Dear Readers

I have a question about facets and doing some filtering based on facets.

In the moment I am using hibernate search in combination with bobobrowse
for facetting and I am thinking about switching to ES. But before that I
would like to check whether I can still get the same functionality.

lets asume that I have an index about cars and some facets -- eg. model and
color.

color
[ ] red (10)
[ ] blue (5)
[ ] green (2)

model
[ ] bmw (4)
[ ] vw (5)
[ ] ford (8)

if I select a model I would like to get only color facets for that model,
but I still would like to get facets for all models. eg:

color
[ ] red (2)
[ ] blue (2)
[ ] green (1)

model
[ ] bmw (4)
[x] vw (5)
[ ] ford (8)

I have searched I did not find an example about this usecase. Is this
possible and if yes, how do I filter a query to get these results?

Kind 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9d1f3008-aff2-4936-8e6c-7611734e7418%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Facets work on the documents returned by the query. This behavior will not
work in your case since you would like to gather facets on a greater set of
documents, not just the ones returned by the query. To solve this issue,
elasticsearch provides a post filter, which affects the result document
set, but not the set of documents that the facets work on.

The term "filter" is a bit overloaded in elasticsearch, so the team renamed
the post filter to a more explicit "post_filter":

The post filter documentation has some insight on how the filters affect
the facets. In your case, you want a filtered query (

)
with the color as the filter, but the model filter will be applied as a
post filter. Hopefully this makes sense. :slight_smile:

Cheers,

Ivan

On Fri, Dec 27, 2013 at 9:41 AM, Volker svs@klest.de wrote:

Dear Readers

I have a question about facets and doing some filtering based on facets.

In the moment I am using hibernate search in combination with bobobrowse
for facetting and I am thinking about switching to ES. But before that I
would like to check whether I can still get the same functionality.

lets asume that I have an index about cars and some facets -- eg. model
and color.

color
red (10)
blue (5)
green (2)

model
bmw (4)
vw (5)
ford (8)

if I select a model I would like to get only color facets for that model,
but I still would like to get facets for all models. eg:

color
red (2)
blue (2)
green (1)

model
bmw (4)
vw (5)
ford (8)

I have searched I did not find an example about this usecase. Is this
possible and if yes, how do I filter a query to get these results?

Kind 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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/9d1f3008-aff2-4936-8e6c-7611734e7418%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDj9Q9EsfvH5%2BE1AkZiCZLVuq3RZkSrRFeaW_NM3Uc6Gw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dear Ivan

thank you very much for your pointers. I will read through it and come
back, if I have further questions!

thanks

Am Freitag, 27. Dezember 2013 18:58:13 UTC+1 schrieb Ivan Brusic:

Facets work on the documents returned by the query. This behavior will
not work in your case since you would like to gather facets on a greater
set of documents, not just the ones returned by the query. To solve this
issue, elasticsearch provides a post filter, which affects the result
document set, but not the set of documents that the facets work on.

The term "filter" is a bit overloaded in elasticsearch, so the team
renamed the post filter to a more explicit "post_filter":

Elasticsearch Platform — Find real-time answers at scale | Elastic
Rename filter param to search api "post_filter" · Issue #4119 · elastic/elasticsearch · GitHub

The post filter documentation has some insight on how the filters affect
the facets. In your case, you want a filtered query (
Elasticsearch Platform — Find real-time answers at scale | Elastic )
with the color as the filter, but the model filter will be applied as a
post filter. Hopefully this makes sense. :slight_smile:

Cheers,

Ivan

On Fri, Dec 27, 2013 at 9:41 AM, Volker <s...@klest.de <javascript:>>wrote:

Dear Readers

I have a question about facets and doing some filtering based on facets.

In the moment I am using hibernate search in combination with bobobrowse
for facetting and I am thinking about switching to ES. But before that I
would like to check whether I can still get the same functionality.

lets asume that I have an index about cars and some facets -- eg. model
and color.

color
red (10)
blue (5)
green (2)

model
bmw (4)
vw (5)
ford (8)

if I select a model I would like to get only color facets for that model,
but I still would like to get facets for all models. eg:

color
red (2)
blue (2)
green (1)

model
bmw (4)
vw (5)
ford (8)

I have searched I did not find an example about this usecase. Is this
possible and if yes, how do I filter a query to get these results?

Kind 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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/9d1f3008-aff2-4936-8e6c-7611734e7418%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/85f17064-1226-4f0b-9435-2b17790afd4e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hopefully this makes sense. :slight_smile:

after reading through your provided links... not totally :wink:

If I apply the selected facet before the the facet calculation, the facet
will count only elements, that are part of the result. That would mean,
that I would not get numbers for the not selected models (in this case no
numbers for bmw and ford).

If I apply the selected facet as a post_filter, I will get the correct
numbers for the unselected models, but the facets for the color does not
represent the numbers for the selected model, but for all models.

But probably I have not understood it, as it was meant. :slight_smile:

Could you please elaborate further, how the query/filter for a selected
facet should be formulated? I have not found any example for this. If there
is one online, I would appreciate a link to that example.

Kind regards

Am Freitag, 27. Dezember 2013 18:58:13 UTC+1 schrieb Ivan Brusic:

Facets work on the documents returned by the query. This behavior will
not work in your case since you would like to gather facets on a greater
set of documents, not just the ones returned by the query. To solve this
issue, elasticsearch provides a post filter, which affects the result
document set, but not the set of documents that the facets work on.

The term "filter" is a bit overloaded in elasticsearch, so the team
renamed the post filter to a more explicit "post_filter":

Elasticsearch Platform — Find real-time answers at scale | Elastic
Rename filter param to search api "post_filter" · Issue #4119 · elastic/elasticsearch · GitHub

The post filter documentation has some insight on how the filters affect
the facets. In your case, you want a filtered query (
Elasticsearch Platform — Find real-time answers at scale | Elastic )
with the color as the filter, but the model filter will be applied as a
post filter. Hopefully this makes sense. :slight_smile:

Cheers,

Ivan

On Fri, Dec 27, 2013 at 9:41 AM, Volker <s...@klest.de <javascript:>>wrote:

Dear Readers

I have a question about facets and doing some filtering based on facets.

In the moment I am using hibernate search in combination with bobobrowse
for facetting and I am thinking about switching to ES. But before that I
would like to check whether I can still get the same functionality.

lets asume that I have an index about cars and some facets -- eg. model
and color.

color
red (10)
blue (5)
green (2)

model
bmw (4)
vw (5)
ford (8)

if I select a model I would like to get only color facets for that model,
but I still would like to get facets for all models. eg:

color
red (2)
blue (2)
green (1)

model
bmw (4)
vw (5)
ford (8)

I have searched I did not find an example about this usecase. Is this
possible and if yes, how do I filter a query to get these results?

Kind 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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/9d1f3008-aff2-4936-8e6c-7611734e7418%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/2609a3ee-1124-4bc1-95e6-c6e7cdb06128%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

After reading your scenario again, I have modified slightly my suggestion.
You would still need to use a post filter since the facets need to work on
set of documents that is greater than the set returned. You can apply the
same post filter as a facet filter on the facet you want to reduce. Here is
an example:

--
Ivan

On Mon, Dec 30, 2013 at 7:57 AM, Volker svs@klest.de wrote:

Hopefully this makes sense. :slight_smile:

after reading through your provided links... not totally :wink:

If I apply the selected facet before the the facet calculation, the facet
will count only elements, that are part of the result. That would mean,
that I would not get numbers for the not selected models (in this case no
numbers for bmw and ford).

If I apply the selected facet as a post_filter, I will get the correct
numbers for the unselected models, but the facets for the color does not
represent the numbers for the selected model, but for all models.

But probably I have not understood it, as it was meant. :slight_smile:

Could you please elaborate further, how the query/filter for a selected
facet should be formulated? I have not found any example for this. If there
is one online, I would appreciate a link to that example.

Kind regards

Am Freitag, 27. Dezember 2013 18:58:13 UTC+1 schrieb Ivan Brusic:

Facets work on the documents returned by the query. This behavior will
not work in your case since you would like to gather facets on a greater
set of documents, not just the ones returned by the query. To solve this
issue, elasticsearch provides a post filter, which affects the result
document set, but not the set of documents that the facets work on.

The term "filter" is a bit overloaded in elasticsearch, so the team
renamed the post filter to a more explicit "post_filter":

Elasticsearch Platform — Find real-time answers at scale | Elastic
reference/current/search-request-post-filter.html
Rename filter param to search api "post_filter" · Issue #4119 · elastic/elasticsearch · GitHub

The post filter documentation has some insight on how the filters affect
the facets. In your case, you want a filtered query (
Elasticsearch Platform — Find real-time answers at scale | Elastic
reference/current/query-dsl-filtered-query.html ) with the color as the
filter, but the model filter will be applied as a post filter. Hopefully
this makes sense. :slight_smile:

Cheers,

Ivan

On Fri, Dec 27, 2013 at 9:41 AM, Volker s...@klest.de wrote:

Dear Readers

I have a question about facets and doing some filtering based on facets.

In the moment I am using hibernate search in combination with bobobrowse
for facetting and I am thinking about switching to ES. But before that I
would like to check whether I can still get the same functionality.

lets asume that I have an index about cars and some facets -- eg. model
and color.

color
red (10)
blue (5)
green (2)

model
bmw (4)
vw (5)
ford (8)

if I select a model I would like to get only color facets for that
model, but I still would like to get facets for all models. eg:

color
red (2)
blue (2)
green (1)

model
bmw (4)
vw (5)
ford (8)

I have searched I did not find an example about this usecase. Is this
possible and if yes, how do I filter a query to get these results?

Kind 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 elasticsearc...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/
msgid/elasticsearch/9d1f3008-aff2-4936-8e6c-7611734e7418%
40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/2609a3ee-1124-4bc1-95e6-c6e7cdb06128%40googlegroups.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQC1i0wUL2gMVEt37PdZLNZXyTi7PTNGKUzDedR6Gpx-5w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dear Ivan

thank you very much for your fast and helpful response. I will create some
demo data and play with your snippet.

I really appreciate your help!

btw... I think my scenario is a very standard scenario for working with
facets -- e.g. every online shop is working in this fashion with facets.

kind regards
Volker

Am Montag, 30. Dezember 2013 18:36:31 UTC+1 schrieb Ivan Brusic:

After reading your scenario again, I have modified slightly my suggestion.
You would still need to use a post filter since the facets need to work on
set of documents that is greater than the set returned. You can apply the
same post filter as a facet filter on the facet you want to reduce. Here is
an example:

facet filter example · GitHub

--
Ivan

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/18a41661-021b-4833-86f1-423223da7a20%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hey

Small correction: When using the global flag, facets ignore the query. See

That might help in your case (though from my experience it is likely that
you will end up with a couple of facets, from which each has a different
facet filter. But your mileage may vary).

--Alex

On Fri, Dec 27, 2013 at 6:58 PM, Ivan Brusic ivan@brusic.com wrote:

Facets work on the documents returned by the query. This behavior will
not work in your case since you would like to gather facets on a greater
set of documents, not just the ones returned by the query. To solve this
issue, elasticsearch provides a post filter, which affects the result
document set, but not the set of documents that the facets work on.

The term "filter" is a bit overloaded in elasticsearch, so the team
renamed the post filter to a more explicit "post_filter":

Elasticsearch Platform — Find real-time answers at scale | Elastic
Rename filter param to search api "post_filter" · Issue #4119 · elastic/elasticsearch · GitHub

The post filter documentation has some insight on how the filters affect
the facets. In your case, you want a filtered query (
Elasticsearch Platform — Find real-time answers at scale | Elastic )
with the color as the filter, but the model filter will be applied as a
post filter. Hopefully this makes sense. :slight_smile:

Cheers,

Ivan

On Fri, Dec 27, 2013 at 9:41 AM, Volker svs@klest.de wrote:

Dear Readers

I have a question about facets and doing some filtering based on facets.

In the moment I am using hibernate search in combination with bobobrowse
for facetting and I am thinking about switching to ES. But before that I
would like to check whether I can still get the same functionality.

lets asume that I have an index about cars and some facets -- eg. model
and color.

color
red (10)
blue (5)
green (2)

model
bmw (4)
vw (5)
ford (8)

if I select a model I would like to get only color facets for that model,
but I still would like to get facets for all models. eg:

color
red (2)
blue (2)
green (1)

model
bmw (4)
vw (5)
ford (8)

I have searched I did not find an example about this usecase. Is this
possible and if yes, how do I filter a query to get these results?

Kind 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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/9d1f3008-aff2-4936-8e6c-7611734e7418%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDj9Q9EsfvH5%2BE1AkZiCZLVuq3RZkSrRFeaW_NM3Uc6Gw%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-FX_La_JB3kyEp7af%2B3A2hEQ2DQ2x0skFi-c_fFppPjw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.