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 <[email protected]
> <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 [email protected] <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 [email protected].
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.