# Or operator in expression

**URL:** https://discuss.elastic.co/t/or-operator-in-expression/105591
**Category:** Elasticsearch
**Created:** [October 27, 2017, 3:21pm UTC](https://discuss.elastic.co/t/or-operator-in-expression/105591 "2017-10-27T15:21:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![afonso.ribeiro](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@afonso.ribeiro](https://discuss.elastic.co/u/afonso.ribeiro)
#### Post date: [October 27, 2017, 3:21pm UTC](https://discuss.elastic.co/t/or-operator-in-expression/105591/1 "2017-10-27T15:21:35Z")

</div>

Hi guys,

I'm trying to convert the following expression to a elasticseach query.

Field 1 != X or Field 2 != Y

Can you help me translate this to elasticsearch?

Thank you very much

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [October 27, 2017, 11:38pm UTC](https://discuss.elastic.co/t/or-operator-in-expression/105591/2 "2017-10-27T23:38:33Z")

</div>

```auto
DELETE test

PUT test/doc/_bulk?refresh=true
{"index": {"_id": "1"}}
{"field1": "X","field2": "Y"}
{"index": {"_id": "2"}}
{"field1": "A","field2": "Y"}
{"index": {"_id": "3"}}
{"field1": "X","field2": "B"}
{"index": {"_id": "5"}}
{"field1": "A","field2": "B"}

GET test/doc/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "bool": {
            "must": [
              {
                "match": {
                  "field1": "X"
                }
              },
              {
                "match": {
                  "field2": "Y"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![afonso.ribeiro](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@afonso.ribeiro](https://discuss.elastic.co/u/afonso.ribeiro)
#### Post date: [October 30, 2017, 3:47pm UTC](https://discuss.elastic.co/t/or-operator-in-expression/105591/3 "2017-10-30T15:47:15Z")

</div>

It worked.

Thank you very much for the help.

---

<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: [November 27, 2017, 3:47pm UTC](https://discuss.elastic.co/t/or-operator-in-expression/105591/4 "2017-11-27T15:47:33Z")

</div>

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