Filters: odd behavior

Hi everyone,
I have a doubt about Filters.

If I have more than one filter, in a filtered query, are they executed in
the defined order? And, are they filtering in a 'chain' mode, i.e. using
the results of the previous filters?

Thanks in advance as always.

--
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/d528067f-5042-4667-bcbc-38dcde87010a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

They are indeed executed in the defined order. Filters that are more
specific should be placed early on and those that cannot be cached
(geo/timebased) should be placed last.

Cheers,

Ivan

On Thu, Oct 16, 2014 at 5:16 AM, @mromagnoli marce.romagnoli@gmail.com
wrote:

Hi everyone,
I have a doubt about Filters.

If I have more than one filter, in a filtered query, are they executed in
the defined order? And, are they filtering in a 'chain' mode, i.e. using
the results of the previous filters?

Thanks in advance as always.

--
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/d528067f-5042-4667-bcbc-38dcde87010a%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/d528067f-5042-4667-bcbc-38dcde87010a%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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%3DcQASJatGfPg2kP%3D8soiHvvxKDZKJ6qkK0FyfZT4B2x_7Qw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

And there is post-filter as well:

Regards,
Alex.

Personal: http://www.outerthoughts.com/ and @arafalov
Solr resources and newsletter: http://www.solr-start.com/ and @solrstart
Solr popularizers community: Sign Up | LinkedIn

On 17 October 2014 16:27, Ivan Brusic ivan@brusic.com wrote:

They are indeed executed in the defined order. Filters that are more
specific should be placed early on and those that cannot be cached
(geo/timebased) should be placed last.

Cheers,

Ivan

On Thu, Oct 16, 2014 at 5:16 AM, @mromagnoli marce.romagnoli@gmail.com
wrote:

Hi everyone,
I have a doubt about Filters.

If I have more than one filter, in a filtered query, are they executed in
the defined order? And, are they filtering in a 'chain' mode, i.e. using the
results of the previous filters?

Thanks in advance as always.

--
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/d528067f-5042-4667-bcbc-38dcde87010a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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%3DcQASJatGfPg2kP%3D8soiHvvxKDZKJ6qkK0FyfZT4B2x_7Qw%40mail.gmail.com.

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

--
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/CAEFAe-GLae4nZ7hFLxfGs9tQ%2BC2SD%2Bvr7CsXv97sFcwEcsnpTg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Thanks guys for your responses.

My question was due an strange behavior when using 'not' and 'geo_distance'
filters.

I want to filter some results that have undesirable words, such as 'sex',
'xxx', etc... And then geo filter those good results, but if I place 'not'
filter first, then when geo filter is applied, it retrieves results with
that not wanted words in it. If I place geo filter first, and then 'not'
filter, geo filter seems not to be executed or something, because results
are not accurate for that filter, instead, they still being good results
with no bad words.

I am using it like this:

{
"query": {
"filtered": {
"query": {...},
"filter": [
[{
"geo_distance": {
"distance": "30km",
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050"
}
}
}],
[{
"not": {
"filter": {
"query": {
"terms": {
"_all": ["sex", "xxx", "sexshop"]
}
}
}
}
}]
]
}
},
"from": 0,
"size": "10",
"sort": {
"_geo_distance": {
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050",
"order": "desc"
}
},
"_score": "desc"
}
}

It seems like the last filter is executed correctly.

Thanks,

Marce

El jueves, 16 de octubre de 2014 09:16:43 UTC-3, @mromagnoli escribió:

Hi everyone,
I have a doubt about Filters.

If I have more than one filter, in a filtered query, are they executed in
the defined order? And, are they filtering in a 'chain' mode, i.e. using
the results of the previous filters?

Thanks in advance as always.

--
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/4ed1e0ad-9654-40a6-a48a-b753c102d0ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

The structure of your query is odd. Either it is some format that I am not
aware of or the Elasticsearch parser is not doing a good job at determining
it is invalid.

Your two filters should be joined via a bool filter. Sometime like (not
tested):

{
"query": {
"filtered": {
"query": {
....
},
"filter": {
"bool": {
"must": [
{
"geo_distance": {
"distance": "30km",
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050"
}
}
},
{
"not": {
"filter": {
"query": {
"terms": {
"_all": [
"sex",
"xxx",
"sexshop"
]
}
}
}
}
}
]
}
}
}
}
}

--
Ivan

On Sat, Oct 18, 2014 at 7:04 AM, @mromagnoli marce.romagnoli@gmail.com
wrote:

Thanks guys for your responses.

My question was due an strange behavior when using 'not' and
'geo_distance' filters.

I want to filter some results that have undesirable words, such as 'sex',
'xxx', etc... And then geo filter those good results, but if I place 'not'
filter first, then when geo filter is applied, it retrieves results with
that not wanted words in it. If I place geo filter first, and then 'not'
filter, geo filter seems not to be executed or something, because results
are not accurate for that filter, instead, they still being good results
with no bad words.

I am using it like this:

{
"query": {
"filtered": {
"query": {...},
"filter": [
[{
"geo_distance": {
"distance": "30km",
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050"
}
}
}],
[{
"not": {
"filter": {
"query": {
"terms": {
"_all": ["sex", "xxx", "sexshop"]
}
}
}
}
}]
]
}
},
"from": 0,
"size": "10",
"sort": {
"_geo_distance": {
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050",
"order": "desc"
}
},
"_score": "desc"
}
}

It seems like the last filter is executed correctly.

Thanks,

Marce

El jueves, 16 de octubre de 2014 09:16:43 UTC-3, @mromagnoli escribió:

Hi everyone,
I have a doubt about Filters.

If I have more than one filter, in a filtered query, are they executed in
the defined order? And, are they filtering in a 'chain' mode, i.e. using
the results of the previous filters?

Thanks in advance as always.

--
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/4ed1e0ad-9654-40a6-a48a-b753c102d0ae%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/4ed1e0ad-9654-40a6-a48a-b753c102d0ae%40googlegroups.com?utm_medium=email&utm_source=footer
.

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

--
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%3DcQBZoCpy_nbxVTM9v2%2BR7Y2jmAzGMtsRSZ8J-CVgm_yawQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Thanks for answer, Ivan.

You were right, I wrapped all my filters inside bool filters and it seems
everything is working correctly!

Thanks for your time!

Marce

El sábado, 18 de octubre de 2014 15:36:39 UTC-3, Ivan Brusic escribió:

The structure of your query is odd. Either it is some format that I am not
aware of or the Elasticsearch parser is not doing a good job at determining
it is invalid.

Your two filters should be joined via a bool filter. Sometime like (not
tested):

{
"query": {
"filtered": {
"query": {
....
},
"filter": {
"bool": {
"must": [
{
"geo_distance": {
"distance": "30km",
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050"
}
}
},
{
"not": {
"filter": {
"query": {
"terms": {
"_all": [
"sex",
"xxx",
"sexshop"
]
}
}
}
}
}
]
}
}
}
}
}

--
Ivan

On Sat, Oct 18, 2014 at 7:04 AM, @mromagnoli <marce.r...@gmail.com
<javascript:>> wrote:

Thanks guys for your responses.

My question was due an strange behavior when using 'not' and
'geo_distance' filters.

I want to filter some results that have undesirable words, such as 'sex',
'xxx', etc... And then geo filter those good results, but if I place 'not'
filter first, then when geo filter is applied, it retrieves results with
that not wanted words in it. If I place geo filter first, and then 'not'
filter, geo filter seems not to be executed or something, because results
are not accurate for that filter, instead, they still being good results
with no bad words.

I am using it like this:

{
"query": {
"filtered": {
"query": {...},
"filter": [
[{
"geo_distance": {
"distance": "30km",
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050"
}
}
}],
[{
"not": {
"filter": {
"query": {
"terms": {
"_all": ["sex", "xxx", "sexshop"]
}
}
}
}
}]
]
}
},
"from": 0,
"size": "10",
"sort": {
"_geo_distance": {
"Location.location": {
"lat": "-32.890183",
"lon": "-68.844050",
"order": "desc"
}
},
"_score": "desc"
}
}

It seems like the last filter is executed correctly.

Thanks,

Marce

El jueves, 16 de octubre de 2014 09:16:43 UTC-3, @mromagnoli escribió:

Hi everyone,
I have a doubt about Filters.

If I have more than one filter, in a filtered query, are they executed
in the defined order? And, are they filtering in a 'chain' mode, i.e. using
the results of the previous filters?

Thanks in advance as always.

--
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/4ed1e0ad-9654-40a6-a48a-b753c102d0ae%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/4ed1e0ad-9654-40a6-a48a-b753c102d0ae%40googlegroups.com?utm_medium=email&utm_source=footer
.

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

--
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/6499b6c2-379a-400d-bf8d-9087ea2aaa10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.