# Or like in and

**URL:** <https://discuss.elastic.co/t/or-like-in-and/104026>\
**Category:** Elasticsearch\
**Created:** [October 15, 2017, 3:17pm UTC](https://discuss.elastic.co/t/or-like-in-and/104026 "2017-10-15T15:17:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishi\_jag](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rishi\_jag](https://discuss.elastic.co/u/rishi_jag)\
**Post date:** [October 15, 2017, 3:17pm UTC](https://discuss.elastic.co/t/or-like-in-and/104026/1 "2017-10-15T15:17:19Z")

</div>

Need to convert this query in ElasticSearch

WHERE (colD like 'abc%' OR colC like '%abc%') AND (colA IN ('a','b') OR colB IN ('a','b'))

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 15, 2017, 4:12pm UTC](https://discuss.elastic.co/t/or-like-in-and/104026/2 "2017-10-15T16:12:52Z")

</div>

What did you try so far?  
Which part can’t you convert?

Have a look first at bool query.

---

<div class="post-metadata">

**Author:** ![rishi\_jag](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rishi\_jag](https://discuss.elastic.co/u/rishi_jag)\
**Post date:** [October 16, 2017, 5:31am UTC](https://discuss.elastic.co/t/or-like-in-and/104026/3 "2017-10-16T05:31:20Z")

</div>

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "dis_max" : {
				"queries" : [
					{
						"wildcard" : { "colD" : "hil*" }
						},
						{
						"wildcard" : { "colC" : "hil*" }
						}
						
				]
			}
        },
        {
						"match" : { "colA" : "10216" }
						}
      ],
      "minimum_should_match": 1
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 16, 2017, 6:19am UTC](https://discuss.elastic.co/t/or-like-in-and/104026/4 "2017-10-16T06:19:35Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

I edited your post.

The sample query you pasted does not really look like to the one you asked for.

Was:

```
WHERE (colD like 'abc%' OR colC like '%abc%') AND (colA IN ('a','b') OR colB IN ('a','b'))

```

And you wrote something with `hil*` and `colA=10216`.

Let me give you some advices:

- Don't use wildcards
- Use the bool query. `or` clauses can be translated as `should` clauses. `and` clauses can be translated as `must` clauses.
- You can use bool queries inside bool queries. Here I'd write something like (not tested):

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "wildcard": { "colD": "'abc%" } 
              },{
                "wildcard": { "colC": "'%abc%" } 
              }
            ]
          }
        }, {
          "bool": {
            "should": [
              {
                 // colA IN ('a','b')
              },{
                 // colB IN ('a','b')
              }
            ]
          }
        }
      ]
    }
  }
}

```

If you need more help, please provide a full recreation script as described in

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

It will help to better understand what you are doing.  
Please, try to keep the example as simple as possible.

---

<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 13, 2017, 6:20am UTC](https://discuss.elastic.co/t/or-like-in-and/104026/5 "2017-11-13T06:20:41Z")

</div>

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