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

Spatial filters stomp on existing filters in ElasticSearch backend #566

Closed
wants to merge 2 commits into from

Conversation

joshdrake
Copy link
Contributor

Narrow filters are applied before the spatial queries using a query filter. If spatial filtering is performed, these filters are stomped on. This can be easily reproduced with a basic case:

ninth_and_mass = Point(-95.23592948913574, 38.96753407043678)
max_dist = D(mi=2)
sqs = SearchQuerySet().models(Shop).dwithin('location', ninth_and_mass, max_dist)

This will generate a filter fragment looking like this:

{
    "filtered": {
        "filter": {
            "geo_distance": {
                "distance": 3.218688, 
                "location": {
                    "lat": 38.967534, 
                    "lon": -95.235929
                }
            }
        }
    }
}

... when it should be this:

{
    "filtered": {
        "filter": {
            "and": [
                {
                    "fquery": {
                        "_cache": true, 
                        "query": {
                            "query_string": {
                                "query": "django_ct:(shops.shop)"
                            }
                        }
                    }
                }, 
                {
                    "geo_distance": {
                        "distance": 3.218688, 
                        "location": {
                            "lat": 38.967534, 
                            "lon": -95.235929
                        }
                    }
                }
            ]
        }
    }
}

I've submitted a pull request to correct this issue.

@jezdez
Copy link
Contributor

jezdez commented Jun 20, 2012

I've pulled the first commit, please feel free to open a new pull request about d5cc42f.

@jezdez jezdez closed this Jun 20, 2012
jezdez added a commit that referenced this pull request Dec 3, 2012
…. This is basically the second part of #566. Thanks to Josh Drake for the initial patch.
floppya pushed a commit to floppya/django-haystack that referenced this pull request Mar 29, 2013
…. This is basically the second part of django-haystack#566. Thanks to Josh Drake for the initial patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants