# How to prepare search query for OR operator?

**URL:** <https://discuss.elastic.co/t/how-to-prepare-search-query-for-or-operator/7612>\
**Category:** Elasticsearch\
**Created:** [May 9, 2012, 9:19am UTC](https://discuss.elastic.co/t/how-to-prepare-search-query-for-or-operator/7612 "2012-05-09T09:19:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [May 9, 2012, 9:19am UTC](https://discuss.elastic.co/t/how-to-prepare-search-query-for-or-operator/7612/1 "2012-05-09T09:19:01Z")

</div>

Hi

I want to search any of list(pen, pencil,ink) from index.

I MySQL database we used following query :

select \* from field where type in(pen,pencil,ink);

extract what I want to implement with query\_String,please help me.

Thanks

---

<div class="post-metadata">

**Author:** ![Andrew\_at\_DataFeedFi](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andrew\_at\_DataFeedFi](https://discuss.elastic.co/u/Andrew_at_DataFeedFi)\
**Post date:** [May 9, 2012, 2:31pm UTC](https://discuss.elastic.co/t/how-to-prepare-search-query-for-or-operator/7612/2 "2012-05-09T14:31:29Z")

</div>

I don't think you can efficiently do OR conditions from simple search  
URI.  
Better to use Query DSL.  
If you are planning to use ES at all you should learn Query DSL there  
is no way around it.

here is the link to boolean query DSL:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On May 9, 4:19 am, sam [mishra.sam...@gmail.com](mailto:mishra.sam...@gmail.com) wrote:

> Hi
> 
> I want to search any of list(pen, pencil,ink) from index.
> 
> I MySQL database we used following query :
> 
> select \* from field where type in(pen,pencil,ink);
> 
> extract what I want to implement with query\_String,please help me.
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![drewr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewr/32/7803_2.png) [@drewr](https://discuss.elastic.co/u/drewr)\
**Post date:** [May 9, 2012, 8:37pm UTC](https://discuss.elastic.co/t/how-to-prepare-search-query-for-or-operator/7612/3 "2012-05-09T20:37:15Z")

</div>

sam wrote:

> I want to search any of list(pen, pencil,ink) from index.
> 
> I MySQL database we used following query :
> 
> select \* from field where type in(pen,pencil,ink);
> 
> extract what I want to implement with query\_String,please help me.

You can do it a couple of ways:

type:pen type:pencil type:ink

Or shorter:

type:(pen pencil ink)

Example:

% curl -s 'localhost:9200/test/\_search?q=type:(ink%20pencil)&pretty=1'  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 2,  
"max\_score" : 0.04500804,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "foo",  
"\_id" : "2",  
"\_score" : 0.04500804, "\_source" : {"type":"pencil"}  
}, {  
"\_index" : "test",  
"\_type" : "foo",  
"\_id" : "3",  
"\_score" : 0.04500804, "\_source" : {"type":"ink"}  
} ]  
}

-Drew

---

<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:** [July 6, 2017, 3:29am UTC](https://discuss.elastic.co/t/how-to-prepare-search-query-for-or-operator/7612/4 "2017-07-06T03:29:33Z")

</div>


