# Incorrect prefix query results

**URL:** <https://discuss.elastic.co/t/incorrect-prefix-query-results/12146>\
**Category:** Elasticsearch\
**Created:** [May 28, 2013, 9:48am UTC](https://discuss.elastic.co/t/incorrect-prefix-query-results/12146 "2013-05-28T09:48:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishek\_pandey](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@abhishek\_pandey](https://discuss.elastic.co/u/abhishek_pandey)\
**Post date:** [May 28, 2013, 9:48am UTC](https://discuss.elastic.co/t/incorrect-prefix-query-results/12146/1 "2013-05-28T09:48:39Z")

</div>

prefix query is not returning the correct results..  
in ISO Country data.. my query was

{"query":{"bool":{"must":[{"prefix":{"country.name":"in"}}],"must\_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}  
and the returned result is:  
{ took: 3 timed\_out: false \_shards: { total: 5 successful: 5 failed: 0 }  
hits: { total: 3 max\_score: 1 hits: [ { \_index: restdb \_type: country \_id:  
sX3-aNGBQaOjo-L7zNj7qQ \_score: 1\_source: { id: 519fcbce820ea8950373612b code  
: ID name: INDONESIA } }{ \_index: restdb \_type: country \_id:  
YMXpIxaPRzmkMZqaKQ36pw \_score: 1\_source: { id: 519fcbce820ea895037360e4 code  
: IO name: _BRITISH INDIAN OCEAN TERRITORY_ }}{ \_index: restdb \_type:  
country \_id: Ok9MHCr4RLqjH6oFLX92EA \_score: 1\_source: { id:  
519fcbce820ea8950373612a code: IN name: INDIA }}  
] } }

As, you can see, red coloured data, is not matching prefix query..  
Am i correct i need to do something else.., if not please help me to find  
out correct way to do so, else, give me go ahead, to post this as bug.

--  
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:** ![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:** [May 28, 2013, 12:15pm UTC](https://discuss.elastic.co/t/incorrect-prefix-query-results/12146/2 "2013-05-28T12:15:52Z")

</div>

Because your field is analyzed and broken into token.  
So, country.name is indexed as: british,indian,ocean,territory

indian match the PrefixQuery in.

If you set this field to not\_analyzed then, you will have to search for IN (uppercase).

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 28 mai 2013 à 11:48, abhishek.pandey@greenclouds.in a écrit :

> prefix query is not returning the correct results..  
> in ISO Country data.. my query was
> 
> {"query":{"bool":{"must":[{"prefix":{"country.name":"in"}}],"must\_not":,"should":}},"from":0,"size":50,"sort":,"facets":{}}
> 
> and the returned result is:  
> { took: 3 timed\_out: false \_shards: { total: 5 successful: 5 failed: 0 } hits: { total: 3 max\_score: 1 hits: [ { \_index: restdb \_type: country \_id: sX3-aNGBQaOjo-L7zNj7qQ \_score: 1\_source: { id: 519fcbce820ea8950373612b code: ID name: INDONESIA } }{ \_index: restdb \_type: country \_id: YMXpIxaPRzmkMZqaKQ36pw \_score: 1\_source: { id: 519fcbce820ea895037360e4 code: IO name: BRITISH INDIAN OCEAN TERRITORY }}{ \_index: restdb \_type: country \_id: Ok9MHCr4RLqjH6oFLX92EA \_score: 1\_source: { id: 519fcbce820ea8950373612a code: IN name: INDIA }}  
> ] } }
> 
> As, you can see, red coloured data, is not matching prefix query..  
> Am i correct i need to do something else.., if not please help me to find out correct way to do so, else, give me go ahead, to post this as bug.
> 
> --  
> 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:34am UTC](https://discuss.elastic.co/t/incorrect-prefix-query-results/12146/3 "2017-07-06T02:34:24Z")

</div>


