# Query (must be X) and (must (Z or Y)

**URL:** https://discuss.elastic.co/t/query-must-be-x-and-must-z-or-y/87855
**Category:** Elasticsearch
**Created:** [June 1, 2017, 7:45am UTC](https://discuss.elastic.co/t/query-must-be-x-and-must-z-or-y/87855 "2017-06-01T07:45:14Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Tetrapack](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Tetrapack](https://discuss.elastic.co/u/Tetrapack)
#### Post date: [June 1, 2017, 8:05am UTC](https://discuss.elastic.co/t/query-must-be-x-and-must-z-or-y/87855/2 "2017-06-01T08:05:04Z")

</div>

```
GET filebeat-*/log/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "terminationCause": {
              "value": "SUCCESS"
            }
          }
        },{
          "terms": {
            "clientId": [
              "X",
              "Y",
              "Z"
            ]
          }
          
        }
      ]
    }
  }
}

```

This query will retrieve documents with terminationCause = "SUCCESS" and clientsId equals to X, Y or Z

Then A and B will automatically be avoided.

---

_[View the full topic](https://discuss.elastic.co/t/query-must-be-x-and-must-z-or-y/87855)._
