django-haystack / django-haystack/django-haystack

ElasticSearch boolean operators issue: OR behaves like AND if NOT is presented

Open
#1,577 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.