Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query DSL: Wrong result on bool filter with 'must_not' and 'geo_distance' #4130

Closed
Akii opened this issue Nov 8, 2013 · 2 comments
Closed

Comments

@Akii
Copy link

Akii commented Nov 8, 2013

The Bool Filter returns the wrong result when combining the 'must_not' (or 'must') part with a 'should' containing a 'geo_distance' filter.

Consider following example:

curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test
curl -XPUT 'localhost:9200/test/test/_mapping' -d '{"test" : {"properties" : { "prop1" : {"type":"string"}, "location": {"type":"geo_point"}}}}'

curl -XPUT 'localhost:9200/test/test/1' -d '{"prop1": "5", "location":{"lon":"0", "lat":"0"}}'
curl -XPUT 'localhost:9200/test/test/2' -d '{"prop1": "5", "location":{"lon":"0", "lat":"0"}}'
curl -XPUT 'localhost:9200/test/test/3' -d '{"prop1": "4", "location":{"lon":"12", "lat":"12"}}'

Example query 1:

{
"filter" : {
    "bool": {
        "must_not": [
            {
                "terms": {
                    "_id": [
                        "1"
                    ]
                }
            }
        ],
        "should": [
            {
                "term": {
                    "_name": "filter_requirements",
                    "prop1": "5"
                }
            },
            {
                "geo_distance": {
                    "_name": "filter_location",
                    "distance": "6km",
                    "location": {
                        "lat": "12", 
                        "lon": "12"
                    }
                }
            }
        ]
    }
}}}

This returns only the document with the id 3. It should return both, 2 and 3 because 2 also matches the 'should' part. Document with id 1 is excluded as expected.

Example query 2:

{"filter" : {
    "bool": {
        "should": [
            {
                "term": {
                    "_name": "filter_requirements",
                    "prop1": "5"
                }
            },
            {
                "geo_distance": {
                    "_name": "filter_location",
                    "distance": "6km",
                    "location": {
                        "lat": "12",
                        "lon": "12"
                    }
                }
            }
        ]
    }
}}}

This returns all 3 documents as expected. Note that the 'must_not' part has been removed. Bool filter works as expected.

Example query 3:

{"filter" : {
    "bool": {
        "must_not": [
            {
                "terms": {
                    "_id": [                       
                        "1"     
                    ]
                }
            }
        ],                       
        "should": [                            
            {                         
                "term": {        
                    "_name": "filter_requirements",
                    "prop1": "5"   
                }    
            }    
        ]
    }
}}}

This will correctly return only the document with id 2. The example above does not show this.. and it's kinda late now. You can remove either the 'should not' or the 'geo_distance' and the query will execute correctly.

@ghost ghost assigned martijnvg Nov 8, 2013
@martijnvg
Copy link
Member

@Akii Thanks for reporting this! I can verify this issue and will fix it soon.

@Akii
Copy link
Author

Akii commented Nov 8, 2013

Wow that was quick. Thanks a lot!

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Nov 12, 2013
…y are hits.

There is an optimization that executes bit based (slow) filters in the end. Matched docs could be unset if they didn't match with any of these filters. The bug was that also iterator based (fast) filters should be checked.
This change checks all should filters in the end part (if must or must_not clauses exists), so it can now correctly unset matched docs. The current bool filters requires that at least one should clause must match for docs to be match regardless of any other clauses.

Closes elastic#4130
martijnvg added a commit that referenced this issue Nov 13, 2013
…y are hits.

There is an optimization that executes bit based (slow) filters in the end. Matched docs could be unset if they didn't match with any of these filters. The bug was that also iterator based (fast) filters should be checked.
This change checks all should filters in the end part (if must or must_not clauses exists), so it can now correctly unset matched docs. The current bool filters requires that at least one should clause must match for docs to be match regardless of any other clauses.

Closes #4130
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
…y are hits.

There is an optimization that executes bit based (slow) filters in the end. Matched docs could be unset if they didn't match with any of these filters. The bug was that also iterator based (fast) filters should be checked.
This change checks all should filters in the end part (if must or must_not clauses exists), so it can now correctly unset matched docs. The current bool filters requires that at least one should clause must match for docs to be match regardless of any other clauses.

Closes elastic#4130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants