Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sparse retrieval with filters returns results without any text-match #2359

Merged
merged 6 commits into from
Mar 25, 2022

Conversation

tstadel
Copy link
Member

@tstadel tstadel commented Mar 25, 2022

Proposed changes:

  • replace should operator of multi_match with must operator

How to reproduce?

with should:

{
    "size": 10,
    "query": {
        "bool": {
            "should": [
                {"multi_match": {"query": "test", "type": "most_fields", "fields": ["content"]}}
            ],
            "filter": {"term": {"content_type": "text"}}
        }
    }
}

returns

...
"total": {
            "value": 3827,
            "relation": "eq"
        },
...

with must:

{
    "size": 10,
    "query": {
        "bool": {
            "must": [
                {"multi_match": {"query": "test", "type": "most_fields", "fields": ["content"]}}
            ],
            "filter": {"term": {"content_type": "text"}}
        }
    }
}

returns

...
"total": {
            "value": 66,
            "relation": "eq"
        },
...

Status (please check what you already did):

  • First draft (up for discussions & feedback)
  • Final code
  • Added tests

Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Linter isn't happy yet though: haystack/pipelines/utils.py:186:12: E4702: Iterated dict 'calculated_metrics' is being modified inside for loop body, iterate through a copy of it instead. (modified-iterating-dict)
A bonus would be to have a test case for the issue that is fixed by this PR.

@tstadel tstadel merged commit b20a1f8 into master Mar 25, 2022
@tstadel tstadel deleted the es_query_must_match branch March 25, 2022 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants