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

Query DSL: Wrong result on bool filter with 'must' and 'should' clauses #2979

Closed
ssenkevich opened this Issue May 3, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@ssenkevich
Copy link

ssenkevich commented May 3, 2013

ES version is 0.90.0 (from deb package). Count of products in test - 667 (333 in stock and 334 out of stock). 50 products was added less than a month ago (37 in stock and 13 out of stock). One product (in stock) have a "Hot Offer" label.

So, my first query (search_type = count):

{
    "query": {
        "match_all": {}
    },
    "filter": {
        "bool": {
            "should": [
                {"term": {"hotOffer": true}},
                {"range": {"created": {"from": "2013-04-02"}}}
            ]
        }
    }
}

The result is 51 hits. It's correct result.
Now add a 'must' clause to 'bool' filter:

{
    "query": {
        "match_all": {}
    },
    "filter": {
        "bool": {
            "must": {
                "term": {"inStock": true}
            },
            "should": [
                {"term": {"hotOffer": true}},
                {"range": {"created": {"from": "2013-04-02"}}}
            ]
        }
    }
}

The result is 332 hits. It's wrong result (should be 38).
Remove 'range' filter from 'should' clause:

{
    "query": {
        "match_all": {}
    },
    "filter": {
        "bool": {
            "must": {
                "term": {"inStock": true}
            },
            "should": [
                {"term": {"hotOffer": true}}
            ]
        }
    }
}

The result is 319 hits. It's wrong result, again (should be 1).
If a 'bool' filter replace by a combination of 'and' and 'or' filters then all is OK.

{
    "query": {
        "match_all": {}
    },
    "filter": {
        "and": [
            {"term": {"inStock": true}},
            {
                "or": [
                    {"term": {"hotOffer": true}},
                    {"range": {"created": {"from": "2013-04-02"}}}
                ]
            }
        ]
    }
}

The result is 38 hits.

It seems that if both clause (must and should) are in bool filter then results are incorrect. In 0.20.6 all works fine.

@ghost ghost assigned martijnvg May 3, 2013

@martijnvg

This comment has been minimized.

Copy link
Member

martijnvg commented May 3, 2013

This is a bug. I will fix it soon.

@martijnvg martijnvg referenced this issue May 3, 2013

Closed

PR for #2979 #2981

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue May 3, 2013

Fixed issue where 'fast' should filter can make documents that didn't…
… match the must or must_not clause a match again.

Relates to elastic#2979

martijnvg added a commit that referenced this issue May 3, 2013

Fixed issue where 'fast' should filter can make documents that didn't…
… match the must or must_not clause a match again. Relates to #2979

martijnvg added a commit that referenced this issue May 3, 2013

Fixed issue where 'fast' should filter can make documents that didn't…
… match the must or must_not clause a match again. Relates to #2979

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue May 3, 2013

Fixed issue where 'fast' should filter can make documents that didn't…
… match the must or must_not clause a match again.

Relates to elastic#2979

@martijnvg martijnvg closed this May 3, 2013

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Fixed issue where 'fast' should filter can make documents that didn't…
… match the must or must_not clause a match again. Relates to elastic#2979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.