# Question about matchPhraseQuery

**URL:** <https://discuss.elastic.co/t/question-about-matchphrasequery/11731>\
**Category:** Elasticsearch\
**Created:** [April 29, 2013, 2:44pm UTC](https://discuss.elastic.co/t/question-about-matchphrasequery/11731 "2013-04-29T14:44:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yahia](https://avatars.discourse-cdn.com/v4/letter/y/d9b06d/32.png) [@yahia](https://discuss.elastic.co/u/yahia)\
**Post date:** [April 29, 2013, 2:44pm UTC](https://discuss.elastic.co/t/question-about-matchphrasequery/11731/1 "2013-04-29T14:44:33Z")

</div>

Hi all,

I want to create PhraseQuery for two fields as follows:

QueryBuilder queryBuilder1 =  
QueryBuilders.matchPhraseQuery(field1,termExact);  
QueryBuilder queryBuilder2 =  
QueryBuilders.matchPhraseQuery(field2,termExact);

I want my query returning documents that contain the termExact in field1 or  
field2;

how I can proceed,

-Yahia AMMAR

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [April 29, 2013, 9:01pm UTC](https://discuss.elastic.co/t/question-about-matchphrasequery/11731/2 "2013-04-29T21:01:13Z")

</div>

Add queryBuilder1 and queryBuilder2 as should clauses inside a  
BoolQueryBuilder, and set minimumShouldMatch to 1.

Something like:

BoolQueryBuilder orQuery = QueryBuilders.boolQuery();  
orQuery.should(queryBuilder1);  
orQuery.should(queryBuilder2);  
orQuery.minimumNumberShouldMatch(1);

Then issue the orQuery.

On Monday, April 29, 2013 10:44:33 AM UTC-4, Ammar Yahia wrote:

> Hi all,
> 
> I want to create PhraseQuery for two fields as follows:
> 
> QueryBuilder queryBuilder1 =  
> QueryBuilders.matchPhraseQuery(field1,termExact);  
> QueryBuilder queryBuilder2 =  
> QueryBuilders.matchPhraseQuery(field2,termExact);
> 
> I want my query returning documents that contain the termExact in field1  
> or field2;
> 
> how I can proceed,
> 
> -Yahia AMMAR

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![taras](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taras/32/507_2.png) [@taras](https://discuss.elastic.co/u/taras)\
**Post date:** [May 1, 2013, 12:24am UTC](https://discuss.elastic.co/t/question-about-matchphrasequery/11731/3 "2013-05-01T00:24:10Z")

</div>

You will actually get a better performance by using MultiMatch[http://www.elasticsearch.org/guide/reference/query-dsl/multi-match-query/](http://www.elasticsearch.org/guide/reference/query-dsl/multi-match-query/)query.

{"multi\_match":{"fields":["field1","field2"], "type":"phrase", "Great  
Phrase"}}

On Monday, April 29, 2013 2:01:13 PM UTC-7, InquiringMind wrote:

> Add queryBuilder1 and queryBuilder2 as should clauses inside a  
> BoolQueryBuilder, and set minimumShouldMatch to 1.
> 
> Something like:
> 
> BoolQueryBuilder orQuery = QueryBuilders.boolQuery();  
> orQuery.should(queryBuilder1);  
> orQuery.should(queryBuilder2);  
> orQuery.minimumNumberShouldMatch(1);
> 
> Then issue the orQuery.
> 
> On Monday, April 29, 2013 10:44:33 AM UTC-4, Ammar Yahia wrote:
> 
> > Hi all,
> > 
> > I want to create PhraseQuery for two fields as follows:
> > 
> > QueryBuilder queryBuilder1 =  
> > QueryBuilders.matchPhraseQuery(field1,termExact);  
> > QueryBuilder queryBuilder2 =  
> > QueryBuilders.matchPhraseQuery(field2,termExact);
> > 
> > I want my query returning documents that contain the termExact in field1  
> > or field2;
> > 
> > how I can proceed,
> > 
> > -Yahia AMMAR

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:38am UTC](https://discuss.elastic.co/t/question-about-matchphrasequery/11731/4 "2017-07-06T02:38:57Z")

</div>


