# Can I combine documents matching different criteria in one query

**URL:** <https://discuss.elastic.co/t/can-i-combine-documents-matching-different-criteria-in-one-query/8935>\
**Category:** Elasticsearch\
**Created:** [September 5, 2012, 2:34pm UTC](https://discuss.elastic.co/t/can-i-combine-documents-matching-different-criteria-in-one-query/8935 "2012-09-05T14:34:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asif](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Asif](https://discuss.elastic.co/u/Asif)\
**Post date:** [September 5, 2012, 2:34pm UTC](https://discuss.elastic.co/t/can-i-combine-documents-matching-different-criteria-in-one-query/8935/1 "2012-09-05T14:34:40Z")

</div>

Hi,  
I want to search documents that match either of two following twi  
criteria:

documents that have string term "test" in their content field

OR

document having timestamp say "2012-08-30T09:39:14"

I understand that if I wanted to do an AND it would be possible using \*bool  
\*and \*must \*clause; but, I can't understand OR case.

Thanks

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [September 5, 2012, 3:46pm UTC](https://discuss.elastic.co/t/can-i-combine-documents-matching-different-criteria-in-one-query/8935/2 "2012-09-05T15:46:33Z")

</div>

Look at a should clause, that is the equivalent of "OR".

> **[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.

"A boolean query with no |must| clauses, one or more |should| clauses  
must match a document. "

-Paul

On 9/5/2012 7:34 AM, Asif wrote:

> Hi,  
> I want to search documents that match either of two following twi  
> criteria:

--

---

<div class="post-metadata">

**Author:** ![Asif](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Asif](https://discuss.elastic.co/u/Asif)\
**Post date:** [September 6, 2012, 12:00pm UTC](https://discuss.elastic.co/t/can-i-combine-documents-matching-different-criteria-in-one-query/8935/3 "2012-09-06T12:00:54Z")

</div>

thanks; but, I have must clause in the same boolean query. I will try  
should clause and see how it goes.

On Wednesday, September 5, 2012 8:46:20 PM UTC+5, P Hill wrote:

> Look at a should clause, that is the equivalent of "OR".  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html)  
> "A boolean query with no |must| clauses, one or more |should| clauses  
> must match a document. "
> 
> -Paul
> 
> On 9/5/2012 7:34 AM, Asif wrote:
> 
> > Hi,  
> > I want to search documents that match either of two following twi  
> > criteria:

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [September 9, 2012, 6:54am UTC](https://discuss.elastic.co/t/can-i-combine-documents-matching-different-criteria-in-one-query/8935/4 "2012-09-09T06:54:52Z")

</div>

Since you only posted twice in this thread and you changed your criteria  
between them, I suggest you post the entire problem. I'm sure there is  
a combination of clauses and nested queries that will get the job done.

-Paul

On 9/6/2012 5:00 AM, Asif wrote:

> thanks; but, I have must clause in the same boolean query. I will  
> try should clause and see how it goes.

--

---

<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:13am UTC](https://discuss.elastic.co/t/can-i-combine-documents-matching-different-criteria-in-one-query/8935/5 "2017-07-06T03:13:33Z")

</div>


