# Bool Queries - Filtering double negatives

**URL:** <https://discuss.elastic.co/t/bool-queries-filtering-double-negatives/258217>\
**Category:** Elasticsearch\
**Created:** [December 10, 2020, 4:55am UTC](https://discuss.elastic.co/t/bool-queries-filtering-double-negatives/258217 "2020-12-10T04:55:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Kneubuehl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephen_kneubuehl/32/68295_2.png) [@Stephen\_Kneubuehl](https://discuss.elastic.co/u/Stephen_Kneubuehl)\
**Post date:** [December 10, 2020, 4:55am UTC](https://discuss.elastic.co/t/bool-queries-filtering-double-negatives/258217/1 "2020-12-10T04:55:07Z")

</div>

Hey everyone,

I need help with query syntax!

I'm trying to build a compound bool query that filters out documents that do not match a certain criteria, essentially a double negative.

I want to return relevant events for our users, and an attribute of these events is to be either public or private ("private" = true). I want to return public events AND return private events that the user is either attending OR invited to. Stated inversely, I want to return events that are NOT private AND do NOT have the user either attending OR invited. There are also a few other attributes to filter out as you'll see in the example below, such as events where we set "isHidden" = true or "isCanceled" = true.

I have tried various structures, but the closest I can come up with is the following:

```auto
    {
      "query": {
        "bool": {
          "must_not": [
            {
              "term": {
                "isHidden": true
              }
            },
            {
              "term": {
                "isCanceled": true
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "term": {
                      "private": true
                    }
                  }
                ],
                "must_not": [
                  {
                    "term": {
                      "invited": "userId1"
                    }
                  },
                  {
                    "term": {
                      "attenders": "userId1"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }

```

However when I execute this query, it always filters out private events, even ones where the userId1 is included in "invited" field, for example.

How can I properly query this case?

Thank you!

---

<div class="post-metadata">

**Author:** ![Stephen\_Kneubuehl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephen_kneubuehl/32/68295_2.png) [@Stephen\_Kneubuehl](https://discuss.elastic.co/u/Stephen_Kneubuehl)\
**Post date:** [December 21, 2020, 9:51pm UTC](https://discuss.elastic.co/t/bool-queries-filtering-double-negatives/258217/2 "2020-12-21T21:51:01Z")

</div>

Forget this one folks, it was an error in our index. The double negatives do in fact work properly!

---

<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:** [January 18, 2021, 9:51pm UTC](https://discuss.elastic.co/t/bool-queries-filtering-double-negatives/258217/3 "2021-01-18T21:51:02Z")

</div>

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