I've been using a distance filter using regular django query filters within an OR-clause:
# either it's within the preset distance of the location
# OR it's not an in-person event
self.filter(Q(location__distance_lt=(geometry, LOCATION_WITHIN_D)) | ~Q(type=Event.IN_PERSON))
I want to do a similar filtering as part of a haystack query, using SQ:
queryset = queryset.filter(SQ(location__distance_lt=(geometry, LOCATION_WITHIN_D)) | ~SQ(type=Event.IN_PERSON))
but instead I get back the error: not all arguments converted during string formatting
- and that only happens with the distance_lt query part, not the ~SQ(type..)
I'm able to apply the distance filtering with my haystack search query by using
queryset = queryset.dwithin('location', geometry, LOCATION_WITHIN_D)`
but I want to be able to have that 'or' condition in this sub-clause.
Is this even possible with raw querying? How can I construct such a raw query for ElasticSearch and still execute it as part of my haystack query?
You can perform the search against the Elasticsearch connection.