# Phrase query question

**URL:** <https://discuss.elastic.co/t/phrase-query-question/8420>\
**Category:** Elasticsearch\
**Created:** [July 16, 2012, 1:24am UTC](https://discuss.elastic.co/t/phrase-query-question/8420 "2012-07-16T01:24:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sagar\_Mehta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_mehta/32/2138_2.png) [@Sagar\_Mehta](https://discuss.elastic.co/u/Sagar_Mehta)\
**Post date:** [July 16, 2012, 1:24am UTC](https://discuss.elastic.co/t/phrase-query-question/8420/1 "2012-07-16T01:24:33Z")

</div>

Suppose I have a query "a system and method for retrieving". A phrase  
query will return a hit only if a document contains all the terms in  
the phrase. But what if I have a document which has the term:

"a system for retrieving"

but no mention of the keyword "method" anywhere in the document. Is  
there any way to do a phrase query while allowing "deletion" of  
certain terms so that i'd be able to match the above? I can think of  
taking the long query and running smaller sub-phrase queries on it in  
sequence, but I was wondering if there was a way to get this behavior  
out of the box.

---

<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:** [July 16, 2012, 5:48am UTC](https://discuss.elastic.co/t/phrase-query-question/8420/2 "2012-07-16T05:48:58Z")

</div>

By default, a QueryString query is a OR query. So, I think your assertion : "A phrase query will return a hit only if a document contains all the terms in the phrase." is false.

If you query for "a system for retrieving", it will return your document.

## HTH David

Le 16 juil. 2012 à 03:24, Sagar Mehta [svmknicks33@gmail.com](mailto:svmknicks33@gmail.com) a écrit :

> Suppose I have a query "a system and method for retrieving". A phrase  
> query will return a hit only if a document contains all the terms in  
> the phrase. But what if I have a document which has the term:
> 
> "a system for retrieving"
> 
> but no mention of the keyword "method" anywhere in the document. Is  
> there any way to do a phrase query while allowing "deletion" of  
> certain terms so that i'd be able to match the above? I can think of  
> taking the long query and running smaller sub-phrase queries on it in  
> sequence, but I was wondering if there was a way to get this behavior  
> out of the box.

---

<div class="post-metadata">

**Author:** ![Sagar\_Mehta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_mehta/32/2138_2.png) [@Sagar\_Mehta](https://discuss.elastic.co/u/Sagar_Mehta)\
**Post date:** [July 16, 2012, 3:54pm UTC](https://discuss.elastic.co/t/phrase-query-question/8420/3 "2012-07-16T15:54:42Z")

</div>

Ok I see, I was using a Text query below instead of of a QueryString  
query which is why I was getting only full matches. Thanks!

{  
"fields" : ["title", "full"],  
"query" : {  
"text":{  
"full": {  
"query" : "System and method for information",  
"type" : "phrase",  
"slop": 100  
}  
}  
},  
"highlight" : {  
"fields" : {  
"order" : "score",  
"full" : {"fragment\_size" : 200, "number\_of\_fragments" : 3},  
"title" : {"fragment\_size" : 200, "number\_of\_fragments" : 3}  
}  
}  
}

On Jul 15, 10:48 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> By default, a QueryString query is a OR query. So, I think your assertion : "A phrase query will return a hit only if a document contains all the terms in the phrase." is false.
> 
> If you query for "a system for retrieving", it will return your document.
> 
> ## HTH David
> 
> Le 16 juil. 2012 à 03:24,SagarMehta [svmknick...@gmail.com](mailto:svmknick...@gmail.com) a écrit :
> 
> > Suppose I have a query "a system and method for retrieving". A phrase  
> > query will return a hit only if a document contains all the terms in  
> > the phrase. But what if I have a document which has the term:
> 
> > "a system for retrieving"
> 
> > but no mention of the keyword "method" anywhere in the document. Is  
> > there any way to do a phrase query while allowing "deletion" of  
> > certain terms so that i'd be able to match the above? I can think of  
> > taking the long query and running smaller sub-phrase queries on it in  
> > sequence, but I was wondering if there was a way to get this behavior  
> > out of the box.

---

<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:20am UTC](https://discuss.elastic.co/t/phrase-query-question/8420/4 "2017-07-06T03:20:12Z")

</div>

Closed on July 6, 2017, 3:20am UTC


