13👍
I feel this question was not answered. It seems the op was asking how to filter for null entries using haystack.query.SearchQuerySet with an ElasticSearch backend.
In the example above, replace
self.searchqueryset.filter(group__isnull=True)
with
self.searchqueryset.filter(_missing_='group')
Not intuitive, but its the only way I have gotten this to work so far.
14👍
If you are using ElasticSearch, the solution can be done without patching, just using native ElasticSearch:
from haystack.inputs import Raw
self.searchqueryset.exclude(group = Raw("[* TO *]"))
Other way around, filter all documents that have non-emtpy group field:
from haystack.inputs import Raw
self.searchqueryset.filter(group = Raw("[* TO *]"))
This could work for SOLR too and for other Haystack backends applying the same concept but with specific syntax of the backend search language.
References:
- Elastic search query syntax
- Haystack backend implementation for elasticsearch
- Haystack Raw input field
- Thanks to @AlexParakhnevich who provided this link which served me as an inspiration.
- Good to know that Elasticsearch also supports special and more robust “missing” filter
- Postgres function json_array_elements does not found while django's tests
- Django-rest-framwork got AttributeError when attempting to get a value for field
- How to reset virtualenv and pip?
- Why should i use vagrant if i use virtualenv?
- Django migration relation does not exist
3👍
If you’re using SOLR, you’d probably like to have a look at the following links:
1) https://github.com/toastdriven/django-haystack/commit/9332a91a7f0e4b33d7e20aa892d156305c12dfe3
2) https://github.com/toastdriven/django-haystack/issues/163
There’s a patch for SOLR, allowing such queries, but for other backends there’s probably none.
- Login_required decorator on ajax views to return 401 instead of 302
- ValueError: "needs to have a value for field "id" before this many-to-many relationship can be used"
- Acessing POST field data without a form (REST api) using Django