# Query for X Y or Z using match

**URL:** https://discuss.elastic.co/t/query-for-x-y-or-z-using-match/98217
**Category:** Elasticsearch
**Created:** [August 24, 2017, 11:09am UTC](https://discuss.elastic.co/t/query-for-x-y-or-z-using-match/98217 "2017-08-24T11:09:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)
#### Post date: [August 24, 2017, 11:09am UTC](https://discuss.elastic.co/t/query-for-x-y-or-z-using-match/98217/1 "2017-08-24T11:09:26Z")

</div>

Continuing the discussion from [Query (must be X) and (must (Z or Y)](https://discuss.elastic.co/t/query-must-be-x-and-must-z-or-y/87855/2):

Hi I built:

```
GET filebeat-*/log/_search
{
  "query": {
      "bool":{
        "must": [
          "should" : [
            {"match" : {"clientId": "tomer"}}
          ]
        ],
      "must": [
        {"term" : {"terminationCause": "SUCCESS"}}
      ]
      
    }
  }
}

```

The question is there a way to use "match" for multiple terms, instead of the "terms" query?  
(when I simply replace terms with "match" it doesnt work

---

<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: [August 24, 2017, 12:01pm UTC](https://discuss.elastic.co/t/query-for-x-y-or-z-using-match/98217/2 "2017-08-24T12:01:13Z")

</div>

Hi,

You can look at the description of [match query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)

It corresponds to a full text query, then if you want multiple values, juste put in one match query all values you want separated with a space.

Adding the "operator" field to "and" or "or" inside the match query will decide if all terms in the query should be found or not

ex:

```
GET filebeat-*/log/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "clientId": "tomer john billy"
          }
        }
      ]
    }
  }
}

```

This one will retrieve document with clientId is equal to :

- "tomer"

- "john"

- "billy"

this one will retrieve documents where clientId is equal to :

- "tomer john billy"

this one will retrieve documents where clientId is equal to :

- "tomer john" or "john tomer"
- "tomer billy" or "billy tomer"
- "john billy" or "billy john"  
=\> The "minimum\_should\_match" field to 2 impose that corresponding field contains at least 2 values.

Finally, you can add a custom analyser if you wants which will split the phrase differently before searching documents.

Hope it's clear ^^'

---

<div class="post-metadata">

### Author: ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)
#### Post date: [August 28, 2017, 9:20am UTC](https://discuss.elastic.co/t/query-for-x-y-or-z-using-match/98217/3 "2017-08-28T09:20:23Z")

</div>

> [@Tetrapack](#):
>
> Adding the “operator” field to “and” or “or” inside the ma

Thank you very much!  
this was very clear

---

<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: [September 25, 2017, 9:20am UTC](https://discuss.elastic.co/t/query-for-x-y-or-z-using-match/98217/4 "2017-09-25T09:20:41Z")

</div>

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