# Create a query with OR condition in elasticsearch 5.4

**URL:** <https://discuss.elastic.co/t/create-a-query-with-or-condition-in-elasticsearch-5-4/87663>\
**Category:** Elasticsearch\
**Created:** [May 31, 2017, 4:40am UTC](https://discuss.elastic.co/t/create-a-query-with-or-condition-in-elasticsearch-5-4/87663 "2017-05-31T04:40:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajoealex](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ajoealex](https://discuss.elastic.co/u/ajoealex)\
**Post date:** [May 31, 2017, 4:40am UTC](https://discuss.elastic.co/t/create-a-query-with-or-condition-in-elasticsearch-5-4/87663/1 "2017-05-31T04:40:59Z")

</div>

I am creating a query to search a particular text in 3 different fields in my indexed data.  
ie I want a query like

```
where sender='%abc%' OR recipient ="%abc%" OR bcc = "%abc%"

```

I tried to create the query which returns a resultset, but I havn't given an OR condition anywhere.  
Couldn't find "default\_operator": "OR"

```
{
 "query": {
   "bool": {
      "must": [
         {"multi_match": {
             "fields": [
                "sender",
                "bcC",
                "recipient "
             ],
            "query": "abc"               
         }
         
         }
      ]         
   } 
}
}
```

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 31, 2017, 5:51am UTC](https://discuss.elastic.co/t/create-a-query-with-or-condition-in-elasticsearch-5-4/87663/3 "2017-05-31T05:51:47Z")

</div>

The field is called 'operator' when using multi\_match

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#operator-min](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#operator-min)

"multi\_match": {  
"fields": [  
"sender",  
"bcc",  
"recipient"  
],  
"operator": "and"  
}

Make sure you read the documentation and the alternatives to using the  
'and' operator.

---

<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:** [May 31, 2017, 8:32am UTC](https://discuss.elastic.co/t/create-a-query-with-or-condition-in-elasticsearch-5-4/87663/4 "2017-05-31T08:32:20Z")

</div>

`where sender='%abc%' OR recipient ="%abc%" OR bcc = "%abc%"`

this query correspond to something like that

```
{
  "query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "sender": {
              "value": "*abc*"
            }
          }
        },
        {
          "wildcard": {
            "recipient": {
              "value": "*abc*"
            }
          }
        },
        {
          "wildcard": {
            "bbc": {
              "value": "*abc*"
            }
          }
        }
      ]
    }
  }
}

```

or if you want with match queries

```
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "sender": "abc"
          }
        },
        {
          "match": {
            "recipient": "abc"
          }
        },
        {
          "match": {
            "bbc": "abc"
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![ajoealex](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ajoealex](https://discuss.elastic.co/u/ajoealex)\
**Post date:** [May 31, 2017, 9:08am UTC](https://discuss.elastic.co/t/create-a-query-with-or-condition-in-elasticsearch-5-4/87663/5 "2017-05-31T09:08:04Z")

</div>

Thank you very much. The 1st example gave me the what I expected.

---

<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 28, 2017, 9:08am UTC](https://discuss.elastic.co/t/create-a-query-with-or-condition-in-elasticsearch-5-4/87663/6 "2017-06-28T09:08:04Z")

</div>

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