django-haystack / django-haystack/django-haystack
ElasticSearch boolean operators issue: OR behaves like AND if NOT is presented
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 1.3k
- Avg merge
- 3h 18m
- Merged PRs (30d)
- 3
Description
- Tested with the latest Haystack release
- Tested with the current Haystack master branch
Expected behaviour
SearchQuerySet().filter(~SQ(field='value') | SQ(field='value'))
Should return all index records
Actual behaviour
Returns 0 records
Investigation
The specified code generates the next elasticsearch query:
{
"query": {
"query_string" : {
"query" : "(NOT (field:(value)) OR field:(value))"
...
}
}
}
I found if to enclose NOT expression in parentheses ((NOT (filed:(value))) OR filed:(value)) the issue will be resolved.
- Operating system version: Ubuntu 16.04
- Search engine version: ElasticSearch 2.4
- Python version: 2.7.12
- Django version: 1.8.17
- Haystack version: 2.6.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the SearchQuerySet filter expression against Elasticsearch 2.4 and inspect the generated query string shown in the issue. Trace the query-building entry point responsible for NOT and OR grouping; the issue is done when the expression returns all index records and a regression test covers this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, elasticsearch, python
- Domain
- search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100