toastdriven/django-haystack — pull request #566 by joshdrake (2012-05-04 19:33:38+00:00)
Title: Spatial filters stomp on existing filters in ElasticSearch backend

Narrow filters are applied before the spatial queries using a [query filter](http://www.elasticsearch.org/guide/reference/query-dsl/query-filter.html). If spatial filtering is performed, these filters are stomped on. This can be easily reproduced with a basic case:

```python
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:

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

... when it should be this:

```javascript
{
"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.