# Text\_phrase\_prefix not giving the required results, the syntax is exactly as explained at "http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html"

**URL:** <https://discuss.elastic.co/t/text-phrase-prefix-not-giving-the-required-results-the-syntax-is-exactly-as-explained-at-http-www-elasticsearch-org-guide-reference-query-dsl-text-query-html/5572>\
**Category:** Elasticsearch\
**Created:** [October 12, 2011, 6:14am UTC](https://discuss.elastic.co/t/text-phrase-prefix-not-giving-the-required-results-the-syntax-is-exactly-as-explained-at-http-www-elasticsearch-org-guide-reference-query-dsl-text-query-html/5572 "2011-10-12T06:14:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [October 12, 2011, 6:14am UTC](https://discuss.elastic.co/t/text-phrase-prefix-not-giving-the-required-results-the-syntax-is-exactly-as-explained-at-http-www-elasticsearch-org-guide-reference-query-dsl-text-query-html/5572/1 "2011-10-12T06:14:30Z")

</div>

text\_phrase\_prefix is not working for some special cases as:

{  
"query": {  
"text": {  
"searchable.title": {  
"type": "phrase\_prefix",  
\* "query": "b",\*  
"analyzer": "default"  
}  
}  
}  
}

{  
"query": {  
"text": {  
"searchable.title": {  
"type": "phrase\_prefix",  
_"query": "bel",_  
"analyzer": "default"  
}  
}  
}  
}

{  
"query": {  
"text": {  
"searchable.title": {  
"type": "phrase\_prefix",  
_"query": "bl",_  
"analyzer": "default"  
}  
}  
}  
}

The above queries are giving the results but the following query is giving  
no result.  
{  
"query": {  
"text": {  
"searchable.title": {  
"type": "phrase\_prefix",  
_"query": "be",_  
"analyzer": "default"  
}  
}  
}  
}

In all the queries, the difference is the _query keyword_. I don't  
understand how it is searching in the document.  
and please do explain what is the exact functionality of max\_expansions  
parameter.

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [October 12, 2011, 3:51pm UTC](https://discuss.elastic.co/t/text-phrase-prefix-not-giving-the-required-results-the-syntax-is-exactly-as-explained-at-http-www-elasticsearch-org-guide-reference-query-dsl-text-query-html/5572/2 "2011-10-12T15:51:43Z")

</div>

Hi,

do you happen to have recreation script? This would really help. I think  
have seen something similar recently but I did not have a chance to  
investigate further, so I am not sure if I hit the same issue or the problem  
was on my side. So, please, if you have recreation script I would be really  
interested in it.

As for the max\_expansions this is the upper limit to as to how many terms  
with the same prefix will be checked from the index. For example if your  
last term in the prefix phrase query is "he" then ES will try to enumerate  
all matching candidates from the index ("hello","hell","help",...) and  
execute boolean query with all variations. But this can expand to very huge  
candidate set of queries which can result in "Too Many Clauses" exception.  
In this case you can easily setup the max\_expansions to some value that  
still gets your acceptable results but do not run into the exception.

Regards,  
Lukas

On Wed, Oct 12, 2011 at 8:14 AM, Narinder Kaur [narinder.kaur@izap.in](mailto:narinder.kaur@izap.in)wrote:

> text\_phrase\_prefix is not working for some special cases as:
> 
> {  
> "query": {  
> "text": {  
> "searchable.title": {  
> "type": "phrase\_prefix",  
> \* "query": "b",\*  
> "analyzer": "default"  
> }  
> }  
> }  
> }
> 
> {  
> "query": {  
> "text": {  
> "searchable.title": {  
> "type": "phrase\_prefix",  
> _"query": "bel",_  
> "analyzer": "default"  
> }  
> }  
> }  
> }
> 
> {  
> "query": {  
> "text": {  
> "searchable.title": {  
> "type": "phrase\_prefix",  
> _"query": "bl",_  
> "analyzer": "default"  
> }  
> }  
> }  
> }
> 
> The above queries are giving the results but the following query is giving  
> no result.  
> {  
> "query": {  
> "text": {  
> "searchable.title": {  
> "type": "phrase\_prefix",  
> _"query": "be",_  
> "analyzer": "default"  
> }  
> }  
> }  
> }
> 
> In all the queries, the difference is the _query keyword_. I don't  
> understand how it is searching in the document.  
> and please do explain what is the exact functionality of max\_expansions  
> parameter.

---

<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:52am UTC](https://discuss.elastic.co/t/text-phrase-prefix-not-giving-the-required-results-the-syntax-is-exactly-as-explained-at-http-www-elasticsearch-org-guide-reference-query-dsl-text-query-html/5572/3 "2017-07-06T03:52:17Z")

</div>


