# Question about TextQuery

**URL:** <https://discuss.elastic.co/t/question-about-textquery/6599>\
**Category:** Elasticsearch\
**Created:** [February 6, 2012, 1:41am UTC](https://discuss.elastic.co/t/question-about-textquery/6599 "2012-02-06T01:41:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![quain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quain/32/2925_2.png) [@quain](https://discuss.elastic.co/u/quain)\
**Post date:** [February 6, 2012, 1:41am UTC](https://discuss.elastic.co/t/question-about-textquery/6599/1 "2012-02-06T01:41:41Z")

</div>

I'm trying to understand how Text Query works. My goal is to make an  
autocomplete/suggest feature. As below, I insert documents with the  
"title" fields: "quick brown", "quick brown fox", "quiet brow" which  
is analyzed with standard analyzer. I'm trying the Text Query with  
phrase\_prefix ([http://www.elasticsearch.org/guide/reference/query-dsl/](http://www.elasticsearch.org/guide/reference/query-dsl/)  
text-query.html) pretty much exactly as described in the guide, but  
I'm getting no hits with any query I'm using. For example, for "quick  
brown" I would expect to see 2 hits: "quick brown" and "quick brown  
fox".

What am I doing wrong? Is there a better analyzer/query setup I  
should be using for an autocomplete kind of use case?

SET UP:  
curl -XPOST localhost:9200/test -d '{  
"mappings" : {  
"document" : {  
"properties" : {  
"title" : { type: "string", analyzer : "standard" }  
}  
}  
}  
}'  
curl -XPUT '[http://localhost:9200/test/document/1](http://localhost:9200/test/document/1)' -d '{  
"title" : "quick brown"  
}'  
curl -XPUT '[http://localhost:9200/test/document/2](http://localhost:9200/test/document/2)' -d '{  
"title" : "quick brown fox"  
}'  
curl -XPUT '[http://localhost:9200/test/document/3](http://localhost:9200/test/document/3)' -d '{  
"title" : "quiet brown"  
}'

QUERY:  
curl "localhost:9200/test/accounts/\_search?pretty=true" -d '{  
"query" : {  
"text" : {  
"message" : {  
"query" : "quick",  
"type" : "phrase\_prefix"  
}  
}  
}  
}'  
=\> No hits

---

<div class="post-metadata">

**Author:** ![vinhphu1711](https://avatars.discourse-cdn.com/v4/letter/v/a88e4f/32.png) [@vinhphu1711](https://discuss.elastic.co/u/vinhphu1711)\
**Post date:** [February 6, 2012, 2:12am UTC](https://discuss.elastic.co/t/question-about-textquery/6599/2 "2012-02-06T02:12:54Z")

</div>

Hi quain,  
Your query is not correct. Should be:

curl "localhost:9200/test/document/\_search?pretty=true" -d '{  
"query" : {  
"text" : {  
"title" : {  
"query" : "quick",  
"type" : "phrase\_prefix"  
}  
}  
}  
}'

Cheers,  
LTVP  
On Feb 6, 2012, at 9:41 AM, quain wrote:

> I'm trying to understand how Text Query works. My goal is to make an  
> autocomplete/suggest feature. As below, I insert documents with the  
> "title" fields: "quick brown", "quick brown fox", "quiet brow" which  
> is analyzed with standard analyzer. I'm trying the Text Query with  
> phrase\_prefix ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)  
> text-query.html) pretty much exactly as described in the guide, but  
> I'm getting no hits with any query I'm using. For example, for "quick  
> brown" I would expect to see 2 hits: "quick brown" and "quick brown  
> fox".
> 
> What am I doing wrong? Is there a better analyzer/query setup I  
> should be using for an autocomplete kind of use case?
> 
> SET UP:  
> curl -XPOST localhost:9200/test -d '{  
> "mappings" : {  
> "document" : {  
> "properties" : {  
> "title" : { type: "string", analyzer : "standard" }  
> }  
> }  
> }  
> }'  
> curl -XPUT '[http://localhost:9200/test/document/1](http://localhost:9200/test/document/1)' -d '{  
> "title" : "quick brown"  
> }'  
> curl -XPUT '[http://localhost:9200/test/document/2](http://localhost:9200/test/document/2)' -d '{  
> "title" : "quick brown fox"  
> }'  
> curl -XPUT '[http://localhost:9200/test/document/3](http://localhost:9200/test/document/3)' -d '{  
> "title" : "quiet brown"  
> }'
> 
> QUERY:  
> curl "localhost:9200/test/accounts/\_search?pretty=true" -d '{  
> "query" : {  
> "text" : {  
> "message" : {  
> "query" : "quick",  
> "type" : "phrase\_prefix"  
> }  
> }  
> }  
> }'  
> =\> No hits

---

<div class="post-metadata">

**Author:** ![quain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quain/32/2925_2.png) [@quain](https://discuss.elastic.co/u/quain)\
**Post date:** [February 6, 2012, 2:54am UTC](https://discuss.elastic.co/t/question-about-textquery/6599/3 "2012-02-06T02:54:22Z")

</div>

Thanks! That was a silly mistake by me.

On Feb 5, 6:12 pm, Phu Le [le.truong.vinh....@gmail.com](mailto:le.truong.vinh....@gmail.com) wrote:

> Hi quain,  
> Your query is not correct. Should be:
> 
> curl "localhost:9200/test/document/\_search?pretty=true" -d '{  
> "query" : {  
> "text" : {  
> "title" : {  
> "query" : "quick",  
> "type" : "phrase\_prefix"  
> }  
> }  
> }
> 
> }'
> 
> Cheers,  
> LTVP  
> On Feb 6, 2012, at 9:41 AM, quain wrote:
> 
> > I'm trying to understand how Text Query works. My goal is to make an  
> > autocomplete/suggest feature. As below, I insert documents with the  
> > "title" fields: "quick brown", "quick brown fox", "quiet brow" which  
> > is analyzed with standard analyzer. I'm trying the Text Query with  
> > phrase\_prefix ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)  
> > text-query.html) pretty much exactly as described in the guide, but  
> > I'm getting no hits with any query I'm using. For example, for "quick  
> > brown" I would expect to see 2 hits: "quick brown" and "quick brown  
> > fox".
> 
> > What am I doing wrong? Is there a better analyzer/query setup I  
> > should be using for an autocomplete kind of use case?
> 
> > SET UP:  
> > curl -XPOST localhost:9200/test -d '{  
> > "mappings" : {  
> > "document" : {  
> > "properties" : {  
> > "title" : { type: "string", analyzer : "standard" }  
> > }  
> > }  
> > }  
> > }'  
> > curl -XPUT '[http://localhost:9200/test/document/1'-d](http://localhost:9200/test/document/1'-d) '{  
> > "title" : "quick brown"  
> > }'  
> > curl -XPUT '[http://localhost:9200/test/document/2'-d](http://localhost:9200/test/document/2'-d) '{  
> > "title" : "quick brown fox"  
> > }'  
> > curl -XPUT '[http://localhost:9200/test/document/3'-d](http://localhost:9200/test/document/3'-d) '{  
> > "title" : "quiet brown"  
> > }'
> 
> > QUERY:  
> > curl "localhost:9200/test/accounts/\_search?pretty=true" -d '{  
> > "query" : {  
> > "text" : {  
> > "message" : {  
> > "query" : "quick",  
> > "type" : "phrase\_prefix"  
> > }  
> > }  
> > }  
> > }'  
> > =\> No hits

---

<div class="post-metadata">

**Author:** ![quain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quain/32/2925_2.png) [@quain](https://discuss.elastic.co/u/quain)\
**Post date:** [February 6, 2012, 10:33pm UTC](https://discuss.elastic.co/t/question-about-textquery/6599/4 "2012-02-06T22:33:23Z")

</div>

A followup question. Is there a way to prefer results that have the  
phrase at the beginning? For example, if I'm searching for "quick  
brown" to prefer "quick brown fox" over "fox quick brown", etc?

I am looking at the docs. and it seems like you can set a boost to  
certain results. How can I structure something like this to do what I  
want with a phrase\_prefix text query?

Thanks!

On Feb 5, 6:54 pm, quain [quaintena...@gmail.com](mailto:quaintena...@gmail.com) wrote:

> Thanks! That was a silly mistake by me.
> 
> On Feb 5, 6:12 pm, Phu Le [le.truong.vinh....@gmail.com](mailto:le.truong.vinh....@gmail.com) wrote:
> 
> > Hi quain,  
> > Your query is not correct. Should be:
> 
> > curl "localhost:9200/test/document/\_search?pretty=true" -d '{  
> > "query" : {  
> > "text" : {  
> > "title" : {  
> > "query" : "quick",  
> > "type" : "phrase\_prefix"  
> > }  
> > }  
> > }
> 
> > }'
> 
> > Cheers,  
> > LTVP  
> > On Feb 6, 2012, at 9:41 AM, quain wrote:
> 
> > > I'm trying to understand how Text Query works. My goal is to make an  
> > > autocomplete/suggest feature. As below, I insert documents with the  
> > > "title" fields: "quick brown", "quick brown fox", "quiet brow" which  
> > > is analyzed with standard analyzer. I'm trying the Text Query with  
> > > phrase\_prefix ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)  
> > > text-query.html) pretty much exactly as described in the guide, but  
> > > I'm getting no hits with any query I'm using. For example, for "quick  
> > > brown" I would expect to see 2 hits: "quick brown" and "quick brown  
> > > fox".
> 
> > > What am I doing wrong? Is there a better analyzer/query setup I  
> > > should be using for an autocomplete kind of use case?
> 
> > > SET UP:  
> > > curl -XPOST localhost:9200/test -d '{  
> > > "mappings" : {  
> > > "document" : {  
> > > "properties" : {  
> > > "title" : { type: "string", analyzer : "standard" }  
> > > }  
> > > }  
> > > }  
> > > }'  
> > > curl -XPUT '[http://localhost:9200/test/document/1'-d'](http://localhost:9200/test/document/1'-d'){  
> > > "title" : "quick brown"  
> > > }'  
> > > curl -XPUT '[http://localhost:9200/test/document/2'-d'](http://localhost:9200/test/document/2'-d'){  
> > > "title" : "quick brown fox"  
> > > }'  
> > > curl -XPUT '[http://localhost:9200/test/document/3'-d'](http://localhost:9200/test/document/3'-d'){  
> > > "title" : "quiet brown"  
> > > }'
> 
> > > QUERY:  
> > > curl "localhost:9200/test/accounts/\_search?pretty=true" -d '{  
> > > "query" : {  
> > > "text" : {  
> > > "message" : {  
> > > "query" : "quick",  
> > > "type" : "phrase\_prefix"  
> > > }  
> > > }  
> > > }  
> > > }'  
> > > =\> No hits

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 7, 2012, 10:19am UTC](https://discuss.elastic.co/t/question-about-textquery/6599/5 "2012-02-07T10:19:13Z")

</div>

There isn't an option to only restrict it to text at the beginning of the relevant field data.

On Tuesday, February 7, 2012 at 12:33 AM, quain wrote:

> A followup question. Is there a way to prefer results that have the  
> phrase at the beginning? For example, if I'm searching for "quick  
> brown" to prefer "quick brown fox" over "fox quick brown", etc?
> 
> I am looking at the docs. and it seems like you can set a boost to  
> certain results. How can I structure something like this to do what I  
> want with a phrase\_prefix text query?
> 
> Thanks!
> 
> On Feb 5, 6:54 pm, quain \<[quaintena...@gmail.com](mailto:quaintena...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > Thanks! That was a silly mistake by me.
> > 
> > On Feb 5, 6:12 pm, Phu Le \<[le.truong.vinh....@gmail.com](mailto:le.truong.vinh....@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > Hi quain,  
> > > Your query is not correct. Should be:
> > 
> > > curl "localhost:9200/test/document/\_search?pretty=true" -d '{  
> > > "query" : {  
> > > "text" : {  
> > > "title" : {  
> > > "query" : "quick",  
> > > "type" : "phrase\_prefix"  
> > > }  
> > > }  
> > > }
> > 
> > > }'
> > 
> > > Cheers,  
> > > LTVP  
> > > On Feb 6, 2012, at 9:41 AM, quain wrote:
> > 
> > > > I'm trying to understand how Text Query works. My goal is to make an  
> > > > autocomplete/suggest feature. As below, I insert documents with the  
> > > > "title" fields: "quick brown", "quick brown fox", "quiet brow" which  
> > > > is analyzed with standard analyzer. I'm trying the Text Query with  
> > > > phrase\_prefix ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)  
> > > > text-query.html) pretty much exactly as described in the guide, but  
> > > > I'm getting no hits with any query I'm using. For example, for "quick  
> > > > brown" I would expect to see 2 hits: "quick brown" and "quick brown  
> > > > fox".
> > 
> > > > What am I doing wrong? Is there a better analyzer/query setup I  
> > > > should be using for an autocomplete kind of use case?
> > 
> > > > SET UP:  
> > > > curl -XPOST localhost:9200/test -d '{  
> > > > "mappings" : {  
> > > > "document" : {  
> > > > "properties" : {  
> > > > "title" : { type: "string", analyzer : "standard" }  
> > > > }  
> > > > }  
> > > > }  
> > > > }'  
> > > > curl -XPUT '[http://localhost:9200/test/document/1'-d'](http://localhost:9200/test/document/1'-d'){  
> > > > "title" : "quick brown"  
> > > > }'  
> > > > curl -XPUT '[http://localhost:9200/test/document/2'-d'](http://localhost:9200/test/document/2'-d'){  
> > > > "title" : "quick brown fox"  
> > > > }'  
> > > > curl -XPUT '[http://localhost:9200/test/document/3'-d'](http://localhost:9200/test/document/3'-d'){  
> > > > "title" : "quiet brown"  
> > > > }'
> > 
> > > > QUERY:  
> > > > curl "localhost:9200/test/accounts/\_search?pretty=true" -d '{  
> > > > "query" : {  
> > > > "text" : {  
> > > > "message" : {  
> > > > "query" : "quick",  
> > > > "type" : "phrase\_prefix"  
> > > > }  
> > > > }  
> > > > }  
> > > > }'  
> > > > =\> No hits

---

<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:40am UTC](https://discuss.elastic.co/t/question-about-textquery/6599/6 "2017-07-06T03:40:19Z")

</div>


