Exclude one filter per facet


(Fermin Silva) #1

Hi everyone, my first message here!

In my company we are considering to migrate from SOLR to ES, so I'm looking
if all business criteria can be met with ES without to much of a hassle.
So far I have everything pretty much worked out except for filter exclusion.
Let me give you an example:

I want to filter out documents whose field 'A' is equal to 'a', and I want
to facet the field 'A' at the same time, excluding of course the previous
filter.
I know that you can put the filter 'outside' the query in order to get the
facets without that filter applied, like:

ElasticSearch (mind the minor errors that i could have here)

{
"query : { "match_all" : { } },
"filter" : { "term : { "A" : "a" } },
"facets" : {
"A" : { "terms" : { "field" : "A" } } //this should exclude the filter A:a
}
}

SOLR

&q=::
&fq={!tag=Aa}A:a
&facet=true&facet.field={!ex=Aa}A

This is very nice, but what happens if i have multiple filters and facets
that each one should exclude each other?
Example:

filter=A:a
filter=B:b
filter=C:c

facet={exclude filter A:a}A
facet={exclude filter B:b}B
facet={exclude filter C:c}C

That is, for facet A I want to keep all filters except A:a, for facet B all
except B:b, and so on.
The most obvious way would be to do n queries (one per each of the n
facets), but I'd like to stay away from that.

Thanks in advance!
Fermin

--


(Martijn Van Groningen) #2

Hi Fermin,

I think you use the 'facet_filter' for this. Which is described here:
http://www.elasticsearch.org/guide/reference/api/search/facets/index.html

It basically allows you to specify a filter per facet to reduce the
count, so instead of specifying what filters should be excluded, you
specify what filters do apply on a specific facet. This is different
from Solr's excluding facets, but you can basically achieve the
same behavior.

Martijn

On 16 August 2012 18:07, Fermin Silva silvafermn@gmail.com wrote:

Hi everyone, my first message here!

In my company we are considering to migrate from SOLR to ES, so I'm looking
if all business criteria can be met with ES without to much of a hassle.
So far I have everything pretty much worked out except for filter exclusion.
Let me give you an example:

I want to filter out documents whose field 'A' is equal to 'a', and I want
to facet the field 'A' at the same time, excluding of course the previous
filter.
I know that you can put the filter 'outside' the query in order to get the
facets without that filter applied, like:

ElasticSearch (mind the minor errors that i could have here)

{
"query : { "match_all" : { } },
"filter" : { "term : { "A" : "a" } },
"facets" : {
"A" : { "terms" : { "field" : "A" } } //this should exclude the filter A:a
}
}

SOLR

&q=::
&fq={!tag=Aa}A:a
&facet=true&facet.field={!ex=Aa}A

This is very nice, but what happens if i have multiple filters and facets
that each one should exclude each other?
Example:

filter=A:a
filter=B:b
filter=C:c

facet={exclude filter A:a}A
facet={exclude filter B:b}B
facet={exclude filter C:c}C

That is, for facet A I want to keep all filters except A:a, for facet B all
except B:b, and so on.
The most obvious way would be to do n queries (one per each of the n
facets), but I'd like to stay away from that.

Thanks in advance!
Fermin

--

--
Met vriendelijke groet,

Martijn van Groningen

--


(Fermin Silva) #3

Hi Martijn, thanks for the response.

You mean like:

query for items: match_all

Facet A: facet_filter B:b, C:c
Facet B: facet_filter A:a, C:c
Facet C: facet_filter A:a, B:b

'external' filters (do not apply for facets): filter A:a, B:b, C:c

?

2012/8/17 Martijn v Groningen martijn.v.groningen@gmail.com

Hi Fermin,

I think you use the 'facet_filter' for this. Which is described here:
http://www.elasticsearch.org/guide/reference/api/search/facets/index.html

It basically allows you to specify a filter per facet to reduce the
count, so instead of specifying what filters should be excluded, you
specify what filters do apply on a specific facet. This is different
from Solr's excluding facets, but you can basically achieve the
same behavior.

Martijn

On 16 August 2012 18:07, Fermin Silva silvafermn@gmail.com wrote:

Hi everyone, my first message here!

In my company we are considering to migrate from SOLR to ES, so I'm
looking
if all business criteria can be met with ES without to much of a hassle.
So far I have everything pretty much worked out except for filter
exclusion.
Let me give you an example:

I want to filter out documents whose field 'A' is equal to 'a', and I
want
to facet the field 'A' at the same time, excluding of course the previous
filter.
I know that you can put the filter 'outside' the query in order to get
the
facets without that filter applied, like:

ElasticSearch (mind the minor errors that i could have here)

{
"query : { "match_all" : { } },
"filter" : { "term : { "A" : "a" } },
"facets" : {
"A" : { "terms" : { "field" : "A" } } //this should exclude the filter
A:a
}
}

SOLR

&q=::
&fq={!tag=Aa}A:a
&facet=true&facet.field={!ex=Aa}A

This is very nice, but what happens if i have multiple filters and facets
that each one should exclude each other?
Example:

filter=A:a
filter=B:b
filter=C:c

facet={exclude filter A:a}A
facet={exclude filter B:b}B
facet={exclude filter C:c}C

That is, for facet A I want to keep all filters except A:a, for facet B
all
except B:b, and so on.
The most obvious way would be to do n queries (one per each of the n
facets), but I'd like to stay away from that.

Thanks in advance!
Fermin

--

--
Met vriendelijke groet,

Martijn van Groningen

--

--


(Martijn Van Groningen) #4

You mean like:

query for items: match_all

Facet A: facet_filter B:b, C:c
Facet B: facet_filter A:a, C:c
Facet C: facet_filter A:a, B:b
Correct, that is what I meant.

'external' filters (do not apply for facets): filter A:a, B:b, C:c?
No they don't, only for the query result (hits).

Martijn

--


(dmitry.polushkin) #5

Is there are a better solution for now, maybe something with the
aggregations?

On Friday, August 17, 2012 3:50:37 PM UTC+1, Martijn v Groningen wrote:

You mean like:

query for items: match_all

Facet A: facet_filter B:b, C:c
Facet B: facet_filter A:a, C:c
Facet C: facet_filter A:a, B:b
Correct, that is what I meant.

'external' filters (do not apply for facets): filter A:a, B:b, C:c?
No they don't, only for the query result (hits).

Martijn

--
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/7cd5bfd0-c78d-4c9f-b664-2935f703737c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #6