# Same query excluding different id returns different results when it should not

**URL:** <https://discuss.elastic.co/t/same-query-excluding-different-id-returns-different-results-when-it-should-not/176518>\
**Category:** Elasticsearch\
**Created:** [April 12, 2019, 1:04am UTC](https://discuss.elastic.co/t/same-query-excluding-different-id-returns-different-results-when-it-should-not/176518 "2019-04-12T01:04:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscar\_Sanchez\_Sanche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oscar_sanchez_sanche/32/36678_2.png) [@Oscar\_Sanchez\_Sanche](https://discuss.elastic.co/u/Oscar_Sanchez_Sanche)\
**Post date:** [April 12, 2019, 1:04am UTC](https://discuss.elastic.co/t/same-query-excluding-different-id-returns-different-results-when-it-should-not/176518/1 "2019-04-12T01:04:59Z")

</div>

Hi there,

I have a problem where I'm doing the exact same query, or at least i think from what i can tell, and the only thing that im excluding is a custom id field that matches the id im currently visiting, so for example this query excluding id 83011 is this:

```
{
    "from": 0,
    "size": 4,
    "sort": [
        {
            "post_date": {
                "order": "desc"
            }
        }
    ],
    "query": {
        "match_all": {
            "boost": 1
        }
    },
    "post_filter": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "terms": {
                                    "terms.post_tag.slug": [
                                        "all-keto-recipes"
                                    ]
                                }
                            }
                        ]
                    }
                },
                {
                    "bool": {
                        "must_not": {
                            "terms": {
                                "post_id": [
                                    83011
                                ]
                            }
                        }
                    }
                },
                {
                    "term": {
                        "post_type.raw": "post"
                    }
                },
                {
                    "term": {
                        "post_status": "publish"
                    }
                }
            ]
        }
    }
}

```

It returns 3 results.

But if i do this other one excluding other id, for example this:

```
{
    "from": 0,
    "size": 4,
    "sort": [
        {
            "post_date": {
                "order": "desc"
            }
        }
    ],
    "query": {
        "match_all": {
            "boost": 1
        }
    },
    "post_filter": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "terms": {
                                    "terms.post_tag.slug": [
                                        "all-keto-recipes"
                                    ]
                                }
                            }
                        ]
                    }
                },
                {
                    "bool": {
                        "must_not": {
                            "terms": {
                                "post_id": [
                                    79070
                                ]
                            }
                        }
                    }
                },
                {
                    "term": {
                        "post_type.raw": "post"
                    }
                },
                {
                    "term": {
                        "post_status": "publish"
                    }
                }
            ]
        }
    }
}

```

It returns 4, though there's about 70 documents that match the condition "all-keto-recipes" in terms.post\_tag.slug

Could you please advise why is this happening and where is my error?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 10, 2019, 1:05am UTC](https://discuss.elastic.co/t/same-query-excluding-different-id-returns-different-results-when-it-should-not/176518/2 "2019-05-10T01:05:01Z")

</div>

Closed on May 10, 2019, 1:05am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
