# How can I add a second exist query?

**URL:** <https://discuss.elastic.co/t/how-can-i-add-a-second-exist-query/181504>\
**Category:** Elasticsearch\
**Created:** [May 17, 2019, 4:28am UTC](https://discuss.elastic.co/t/how-can-i-add-a-second-exist-query/181504 "2019-05-17T04:28:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [May 17, 2019, 4:28am UTC](https://discuss.elastic.co/t/how-can-i-add-a-second-exist-query/181504/1 "2019-05-17T04:28:59Z")

</div>

Hi,

I got this query which is working fine but instead of only checking for the `error` field I want to check for `error` or `warning` so the documents where either the error field or warning field exists, are returned.

```
GET /_search
{
  "size": 1000,
  "sort": [
              {
                "@timestamp": {
                  "order": "desc"
                }
              }
            ],
  "query": {
    "bool": {
      "must": [
        {
          "range": {
          "@timestamp" : { 
                "gte" : "now-3d"
            }
           }
          },
        {
          "bool": {
            "must": {
              "exists": {
                "field": "error"
              }
            }
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [May 17, 2019, 4:40am UTC](https://discuss.elastic.co/t/how-can-i-add-a-second-exist-query/181504/2 "2019-05-17T04:40:24Z")

</div>

You can do it like this:

```
{
  "size": 1000,
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "@timestamp": {
              "gte": "now-3d"
            }
          }
        }
      ],
      "minimum_should_match": 1,
      "should": [
        {
          "exists": {
            "field": "error"
          }
        },
        {
          "exists": {
            "field": "warning"
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [May 17, 2019, 6:43am UTC](https://discuss.elastic.co/t/how-can-i-add-a-second-exist-query/181504/3 "2019-05-17T06:43:24Z")

</div>

Thanks, that works like a charm.

I can see where I went wrong, everything should be in the same filter.

---

<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:** [June 14, 2019, 6:43am UTC](https://discuss.elastic.co/t/how-can-i-add-a-second-exist-query/181504/4 "2019-06-14T06:43:26Z")

</div>

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