# Query no working

**URL:** <https://discuss.elastic.co/t/query-no-working/2905>\
**Category:** Elasticsearch\
**Created:** [April 11, 2010, 8:45pm UTC](https://discuss.elastic.co/t/query-no-working/2905 "2010-04-11T20:45:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walendo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/walendo/32/3348_2.png) [@Walendo](https://discuss.elastic.co/u/Walendo)\
**Post date:** [April 11, 2010, 8:45pm UTC](https://discuss.elastic.co/t/query-no-working/2905/1 "2010-04-11T20:45:17Z")

</div>

Hi,

I'm using the query string bellow to fetch all the documents whose  
field "nome" starts with jo, sorting by the field "nome".

[http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:["nome"]](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:%5B%22nome%22%5D)

Is it the appropriate query? I need to use the query string due to  
caching constraints.

The result is the bellow:

{"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"6381", "\_source" :  
{"cidade": {"codigo": 6381, "nome": "Jordão", "estado": "ac"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
{"codigo": 5715, "nome": "Joaquim Gomes", "estado": "al"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"1525", "\_source" : {"cidade":  
{"codigo": 1525, "nome": "São José da Tapera", "estado": "al"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"5742", "\_source" : {"cidade":  
{"codigo": 5742, "nome": "São José da Laje", "estado": "al"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"6793", "\_source" : {"cidade":  
{"codigo": 6793, "nome": "Caldas do Jorro", "estado": "ba"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"5760", "\_source" : {"cidade":  
{"codigo": 5760, "nome": "Coronel João Sá", "estado": "ba"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"4841", "\_source" : {"cidade":  
{"codigo": 4841, "nome": "João Dourado", "estado": "ba"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"930", "\_source" : {"cidade":  
{"codigo": 930, "nome": "Mata de São João", "estado": "ba"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"5175", "\_source" : {"cidade":  
{"codigo": 5175, "nome": "São José do Jacuípe", "estado": "ba"}}},  
{"\_index":"ig","\_type":"cidade","\_id":"5784", "\_source" : {"cidade":  
{"codigo": 5784, "nome": "São José da Vitória", "estado": "ba"}}}]}}

Thanks

---

<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:** [April 12, 2010, 12:09am UTC](https://discuss.elastic.co/t/query-no-working/2905/2 "2010-04-12T00:09:37Z")

</div>

The sorting is a bit wrong, here is the updated one:

[http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort)[http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:[\](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:%5B%5C)  
=nome

On Sun, Apr 11, 2010 at 11:45 PM, Walendo [jorge.walendowsky@gmail.com](mailto:jorge.walendowsky@gmail.com)wrote:

> Hi,
> 
> I'm using the query string bellow to fetch all the documents whose  
> field "nome" starts with jo, sorting by the field "nome".
> 
> [http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:)[  
> "nome"]
> 
> Is it the appropriate query? I need to use the query string due to  
> caching constraints.
> 
> The result is the bellow:
> 
> {"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
> 180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"6381", "\_source" :  
> {"cidade": {"codigo": 6381, "nome": "Jordão", "estado": "ac"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
> {"codigo": 5715, "nome": "Joaquim Gomes", "estado": "al"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"1525", "\_source" : {"cidade":  
> {"codigo": 1525, "nome": "São José da Tapera", "estado": "al"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"5742", "\_source" : {"cidade":  
> {"codigo": 5742, "nome": "São José da Laje", "estado": "al"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"6793", "\_source" : {"cidade":  
> {"codigo": 6793, "nome": "Caldas do Jorro", "estado": "ba"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"5760", "\_source" : {"cidade":  
> {"codigo": 5760, "nome": "Coronel João Sá", "estado": "ba"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"4841", "\_source" : {"cidade":  
> {"codigo": 4841, "nome": "João Dourado", "estado": "ba"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"930", "\_source" : {"cidade":  
> {"codigo": 930, "nome": "Mata de São João", "estado": "ba"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"5175", "\_source" : {"cidade":  
> {"codigo": 5175, "nome": "São José do Jacuípe", "estado": "ba"}}},  
> {"\_index":"ig","\_type":"cidade","\_id":"5784", "\_source" : {"cidade":  
> {"codigo": 5784, "nome": "São José da Vitória", "estado": "ba"}}}]}}
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![Walendo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/walendo/32/3348_2.png) [@Walendo](https://discuss.elastic.co/u/Walendo)\
**Post date:** [April 12, 2010, 1:12pm UTC](https://discuss.elastic.co/t/query-no-working/2905/3 "2010-04-12T13:12:46Z")

</div>

Thanks for the tip. I changed it and unfortunatelly the query is still  
not ordering and not filtering for the "nome"s starting with "jo".  
Does it have to do with the language (Portuguese-Brazil) and its  
symbols?

When I set explain=true, the result is the bellow. The question is: is  
it right to use the ConstantScoreQuery or it should use the  
PrefixQuery instead?

{"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"3817", "\_source" :  
{"cidade": {"codigo": 3817, "nome": "Joanésia", "estado":  
"mg"}},"\_explanation":{"value":  
1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"2077", "\_source" : {"cidade":  
{"codigo": 2077, "nome": "Joanópolis", "estado": "sp"}},"\_explanation":  
{"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
{"codigo": 5715, "nome": "Joaquim Gomes", "estado":  
"al"}},"\_explanation":{"value":  
1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"3715", "\_source" : {"cidade":  
{"codigo": 3715, "nome": "Dom Joaquim", "estado":  
"mg"}},"\_explanation":{"value":  
1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"3818", "\_source" : {"cidade":  
{"codigo": 3818, "nome": "Joaquim Felício", "estado":  
"mg"}},"\_explanation":{"value":  
1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"6966", "\_source" : {"cidade":  
{"codigo": 6966, "nome": "Joaquim Egídio", "estado":  
"sp"}},"\_explanation":{"value":  
1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"380", "\_source" : {"cidade":  
{"codigo": 380, "nome": "Joaçaba", "estado": "sc"}},"\_explanation":  
{"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"3357", "\_source" : {"cidade":  
{"codigo": 3357, "nome": "Joaíma", "estado": "mg"}},"\_explanation":  
{"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"381", "\_source" : {"cidade":  
{"codigo": 381, "nome": "Joinville", "estado": "sc"}},"\_explanation":  
{"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}},  
{"\_index":"ig","\_type":"cidade","\_id":"3819", "\_source" : {"cidade":  
{"codigo": 3819, "nome": "Jordânia", "estado": "mg"}},"\_explanation":  
{"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
of:","details":[{"value":1.0,"description":"boost"},{"value":  
1.0,"description":"queryNorm"}]}}]}}

On 11 abr, 21:09, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> The sorting is a bit wrong, here is the updated one:
> 
> [http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort)[http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:[\](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:%5B%5C)  
> =nome
> 
> On Sun, Apr 11, 2010 at 11:45 PM, Walendo [jorge.walendow...@gmail.com](mailto:jorge.walendow...@gmail.com)wrote:
> 
> > Hi,
> 
> > I'm using the query string bellow to fetch all the documents whose  
> > field "nome" starts with jo, sorting by the field "nome".
> 
> > [http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:)[  
> > "nome"]
> 
> > Is it the appropriate query? I need to use the query string due to  
> > caching constraints.
> 
> > The result is the bellow:
> 
> > {"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
> > 180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"6381", "\_source" :  
> > {"cidade": {"codigo": 6381, "nome": "Jordão", "estado": "ac"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
> > {"codigo": 5715, "nome": "Joaquim Gomes", "estado": "al"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"1525", "\_source" : {"cidade":  
> > {"codigo": 1525, "nome": "São José da Tapera", "estado": "al"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"5742", "\_source" : {"cidade":  
> > {"codigo": 5742, "nome": "São José da Laje", "estado": "al"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"6793", "\_source" : {"cidade":  
> > {"codigo": 6793, "nome": "Caldas do Jorro", "estado": "ba"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"5760", "\_source" : {"cidade":  
> > {"codigo": 5760, "nome": "Coronel João Sá", "estado": "ba"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"4841", "\_source" : {"cidade":  
> > {"codigo": 4841, "nome": "João Dourado", "estado": "ba"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"930", "\_source" : {"cidade":  
> > {"codigo": 930, "nome": "Mata de São João", "estado": "ba"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"5175", "\_source" : {"cidade":  
> > {"codigo": 5175, "nome": "São José do Jacuípe", "estado": "ba"}}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"5784", "\_source" : {"cidade":  
> > {"codigo": 5784, "nome": "São José da Vitória", "estado": "ba"}}}]}}
> 
> > Thanks

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 12, 2010, 2:56pm UTC](https://discuss.elastic.co/t/query-no-working/2905/4 "2010-04-12T14:56:01Z")

</div>

On Mon, 2010-04-12 at 06:12 -0700, Walendo wrote:

> Thanks for the tip. I changed it and unfortunatelly the query is still  
> not ordering and not filtering for the "nome"s starting with "jo".  
> Does it have to do with the language (Portuguese-Brazil) and its  
> symbols?

How do the results differ from what you are expecting? Understanding  
what you'd like to achieve will make it easier to suggest the right  
solution.

Clint

> When I set explain=true, the result is the bellow. The question is: is  
> it right to use the ConstantScoreQuery or it should use the  
> PrefixQuery instead?
> 
> {"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
> 180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"3817", "\_source" :  
> {"cidade": {"codigo": 3817, "nome": "JoanÃ©sia", "estado":  
> "mg"}},"\_explanation":{"value":  
> 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"2077", "\_source" : {"cidade":  
> {"codigo": 2077, "nome": "JoanÃ³polis", "estado": "sp"}},"\_explanation":  
> {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
> {"codigo": 5715, "nome": "Joaquim Gomes", "estado":  
> "al"}},"\_explanation":{"value":  
> 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"3715", "\_source" : {"cidade":  
> {"codigo": 3715, "nome": "Dom Joaquim", "estado":  
> "mg"}},"\_explanation":{"value":  
> 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"3818", "\_source" : {"cidade":  
> {"codigo": 3818, "nome": "Joaquim FelÃ­cio", "estado":  
> "mg"}},"\_explanation":{"value":  
> 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"6966", "\_source" : {"cidade":  
> {"codigo": 6966, "nome": "Joaquim EgÃ­dio", "estado":  
> "sp"}},"\_explanation":{"value":  
> 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"380", "\_source" : {"cidade":  
> {"codigo": 380, "nome": "JoaÃ§aba", "estado": "sc"}},"\_explanation":  
> {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"3357", "\_source" : {"cidade":  
> {"codigo": 3357, "nome": "JoaÃ­ma", "estado": "mg"}},"\_explanation":  
> {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"381", "\_source" : {"cidade":  
> {"codigo": 381, "nome": "Joinville", "estado": "sc"}},"\_explanation":  
> {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}},  
> {"\_index":"ig","\_type":"cidade","\_id":"3819", "\_source" : {"cidade":  
> {"codigo": 3819, "nome": "JordÃ¢nia", "estado": "mg"}},"\_explanation":  
> {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> of:","details":[{"value":1.0,"description":"boost"},{"value":  
> 1.0,"description":"queryNorm"}]}}]}}
> 
> On 11 abr, 21:09, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > The sorting is a bit wrong, here is the updated one:
> > 
> > [http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort)[http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:[\](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:%5B%5C)  
> > =nome
> > 
> > On Sun, Apr 11, 2010 at 11:45 PM, Walendo [jorge.walendow...@gmail.com](mailto:jorge.walendow...@gmail.com)wrote:
> > 
> > > Hi,
> > 
> > > I'm using the query string bellow to fetch all the documents whose  
> > > field "nome" starts with jo, sorting by the field "nome".
> > 
> > > [http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:)[  
> > > "nome"]
> > 
> > > Is it the appropriate query? I need to use the query string due to  
> > > caching constraints.
> > 
> > > The result is the bellow:
> > 
> > > {"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
> > > 180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"6381", "\_source" :  
> > > {"cidade": {"codigo": 6381, "nome": "JordÃ£o", "estado": "ac"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
> > > {"codigo": 5715, "nome": "Joaquim Gomes", "estado": "al"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"1525", "\_source" : {"cidade":  
> > > {"codigo": 1525, "nome": "SÃ£o JosÃ© da Tapera", "estado": "al"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"5742", "\_source" : {"cidade":  
> > > {"codigo": 5742, "nome": "SÃ£o JosÃ© da Laje", "estado": "al"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"6793", "\_source" : {"cidade":  
> > > {"codigo": 6793, "nome": "Caldas do Jorro", "estado": "ba"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"5760", "\_source" : {"cidade":  
> > > {"codigo": 5760, "nome": "Coronel JoÃ£o SÃ¡", "estado": "ba"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"4841", "\_source" : {"cidade":  
> > > {"codigo": 4841, "nome": "JoÃ£o Dourado", "estado": "ba"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"930", "\_source" : {"cidade":  
> > > {"codigo": 930, "nome": "Mata de SÃ£o JoÃ£o", "estado": "ba"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"5175", "\_source" : {"cidade":  
> > > {"codigo": 5175, "nome": "SÃ£o JosÃ© do JacuÃ­pe", "estado": "ba"}}},  
> > > {"\_index":"ig","\_type":"cidade","\_id":"5784", "\_source" : {"cidade":  
> > > {"codigo": 5784, "nome": "SÃ£o JosÃ© da VitÃ³ria", "estado": "ba"}}}]}}
> > 
> > > Thanks  
> > > --  
> > > Web Announcements Limited is a company registered in England and Wales,  
> > > with company number 05608868, with registered address at 10 Arvon Road,  
> > > London, N5 1PR.

---

<div class="post-metadata">

**Author:** ![Walendo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/walendo/32/3348_2.png) [@Walendo](https://discuss.elastic.co/u/Walendo)\
**Post date:** [April 12, 2010, 5:49pm UTC](https://discuss.elastic.co/t/query-no-working/2905/5 "2010-04-12T17:49:28Z")

</div>

Fist of all, when I use "jo\*" as the query (preffix query), I expect  
no ocurrences like "Mata de São João", because it doesn't start with  
jo, it contains a word that starts with it instead.

And there are other cities, like João Pessoa, that aren't on the list,  
while Jordânia is.

Thanks.

On 12 abr, 11:56, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> On Mon, 2010-04-12 at 06:12 -0700, Walendo wrote:
> 
> > Thanks for the tip. I changed it and unfortunatelly the query is still  
> > not ordering and not filtering for the "nome"s starting with "jo".  
> > Does it have to do with the language (Portuguese-Brazil) and its  
> > symbols?
> 
> How do the results differ from what you are expecting? Understanding  
> what you'd like to achieve will make it easier to suggest the right  
> solution.
> 
> Clint
> 
> > When I set explain=true, the result is the bellow. The question is: is  
> > it right to use the ConstantScoreQuery or it should use the  
> > PrefixQuery instead?
> 
> > {"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
> > 180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"3817", "\_source" :  
> > {"cidade": {"codigo": 3817, "nome": "Joanésia", "estado":  
> > "mg"}},"\_explanation":{"value":  
> > 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"2077", "\_source" : {"cidade":  
> > {"codigo": 2077, "nome": "Joanópolis", "estado": "sp"}},"\_explanation":  
> > {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
> > {"codigo": 5715, "nome": "Joaquim Gomes", "estado":  
> > "al"}},"\_explanation":{"value":  
> > 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"3715", "\_source" : {"cidade":  
> > {"codigo": 3715, "nome": "Dom Joaquim", "estado":  
> > "mg"}},"\_explanation":{"value":  
> > 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"3818", "\_source" : {"cidade":  
> > {"codigo": 3818, "nome": "Joaquim Felício", "estado":  
> > "mg"}},"\_explanation":{"value":  
> > 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"6966", "\_source" : {"cidade":  
> > {"codigo": 6966, "nome": "Joaquim Egídio", "estado":  
> > "sp"}},"\_explanation":{"value":  
> > 1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"380", "\_source" : {"cidade":  
> > {"codigo": 380, "nome": "Joaçaba", "estado": "sc"}},"\_explanation":  
> > {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"3357", "\_source" : {"cidade":  
> > {"codigo": 3357, "nome": "Joaíma", "estado": "mg"}},"\_explanation":  
> > {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"381", "\_source" : {"cidade":  
> > {"codigo": 381, "nome": "Joinville", "estado": "sc"}},"\_explanation":  
> > {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}},  
> > {"\_index":"ig","\_type":"cidade","\_id":"3819", "\_source" : {"cidade":  
> > {"codigo": 3819, "nome": "Jordânia", "estado": "mg"}},"\_explanation":  
> > {"value":1.0,"description":"ConstantScoreQuery(nome:jo\*), product  
> > of:","details":[{"value":1.0,"description":"boost"},{"value":  
> > 1.0,"description":"queryNorm"}]}}]}}
> 
> > On 11 abr, 21:09, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > The sorting is a bit wrong, here is the updated one:
> 
> > > [http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort)[http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:[\](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:%5B%5C)  
> > > =nome
> 
> > > On Sun, Apr 11, 2010 at 11:45 PM, Walendo [jorge.walendow...@gmail.com](mailto:jorge.walendow...@gmail.com)wrote:
> 
> > > > Hi,
> 
> > > > I'm using the query string bellow to fetch all the documents whose  
> > > > field "nome" starts with jo, sorting by the field "nome".
> 
> > > > [http://localhost:9200/ig/cidade/\_search?size=10&q=nome:jo\*&sort:fields:](http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:)[  
> > > > "nome"]
> 
> > > > Is it the appropriate query? I need to use the query string due to  
> > > > caching constraints.
> 
> > > > The result is the bellow:
> 
> > > > {"\_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":  
> > > > 180,"hits":[{"\_index":"ig","\_type":"cidade","\_id":"6381", "\_source" :  
> > > > {"cidade": {"codigo": 6381, "nome": "Jordão", "estado": "ac"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"5715", "\_source" : {"cidade":  
> > > > {"codigo": 5715, "nome": "Joaquim Gomes", "estado": "al"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"1525", "\_source" : {"cidade":  
> > > > {"codigo": 1525, "nome": "São José da Tapera", "estado": "al"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"5742", "\_source" : {"cidade":  
> > > > {"codigo": 5742, "nome": "São José da Laje", "estado": "al"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"6793", "\_source" : {"cidade":  
> > > > {"codigo": 6793, "nome": "Caldas do Jorro", "estado": "ba"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"5760", "\_source" : {"cidade":  
> > > > {"codigo": 5760, "nome": "Coronel João Sá", "estado": "ba"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"4841", "\_source" : {"cidade":  
> > > > {"codigo": 4841, "nome": "João Dourado", "estado": "ba"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"930", "\_source" : {"cidade":  
> > > > {"codigo": 930, "nome": "Mata de São João", "estado": "ba"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"5175", "\_source" : {"cidade":  
> > > > {"codigo": 5175, "nome": "São José do Jacuípe", "estado": "ba"}}},  
> > > > {"\_index":"ig","\_type":"cidade","\_id":"5784", "\_source" : {"cidade":  
> > > > {"codigo": 5784, "nome": "São José da Vitória", "estado": "ba"}}}]}}
> 
> > > > Thanks
> 
> --  
> Web Announcements Limited is a company registered in England and Wales,  
> with company number 05608868, with registered address at 10 Arvon Road,  
> London, N5 1PR.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 12, 2010, 6:53pm UTC](https://discuss.elastic.co/t/query-no-working/2905/6 "2010-04-12T18:53:58Z")

</div>

On Mon, 2010-04-12 at 10:49 -0700, Walendo wrote:

> Fist of all, when I use "jo\*" as the query (preffix query), I expect  
> no ocurrences like "Mata de SÃ£o JoÃ£o", because it doesn't start with  
> jo, it contains a word that starts with it instead.

Your text is being broken down into "terms" by the analyzer, where a  
term corresponds roughly to a separate word.

The point of full text search is to search for individual words within  
larger blocks of text.

However, if you want the "nome" field to be considered as a whole, then  
you should use a custom analyzer with a 'keyword' tokenizer and a  
'lowercase' filter:  
[http://www.elasticsearch.com/docs/elasticsearch/index\_modules/analysis/](http://www.elasticsearch.com/docs/elasticsearch/index_modules/analysis/)

That way, ï»¿"Dom Joaquim" would be considered as the single term "dom  
joaquim", instead of it being broken down into "dom" ï»¿and "joaquim", as  
is happening now.

ï»¿You can make this custom analyzer available to all indexes by adding  
this to config/elasticsearch.yaml:

index :  
analysis :  
analyzer :  
lower\_term: # this is your name for the analyzer  
type : custom  
tokenizer: keyword  
filter: [lowercase]

Once you have done that, you can use the prefix query, eg:

{ "query": { "prefix": { "nome": "jo"} } }

> And there are other cities, like JoÃ£o Pessoa, that aren't on the list,  
> while JordÃ¢nia is.

Hmm, it looks like ES is using a simple sort rather than a proper  
unicode collation. I've opened an issue  
here: ï»¿[Support unicode collations · Issue #130 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/issue/130)

hope this helps

## clint

Web Announcements Limited is a company registered in England and Wales,  
with company number 05608868, with registered address at 10 Arvon Road,  
London, N5 1PR.

---

<div class="post-metadata">

**Author:** ![Walendo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/walendo/32/3348_2.png) [@Walendo](https://discuss.elastic.co/u/Walendo)\
**Post date:** [April 28, 2010, 1:25pm UTC](https://discuss.elastic.co/t/query-no-working/2905/7 "2010-04-28T13:25:08Z")

</div>

Hi! After a little break, finally I could manage to go on with my  
researches..

I created this Analyzer:

index :  
analysis :  
analyzer :  
palavras :  
type : custom  
tokenizer : keyword  
filter : [lowercase, asciifolding]

The mapping is:

{  
"cidade" : {  
"properties" : {  
"codigo" : {"type" : "integer" , "store" : "yes"},  
"nome" : {"type" : "string", "store" : "yes", "index" : "analyzed",  
"analyzer" : "palavras"},  
"estado" : {"type" : "string", "store" :"yes"}  
}  
}  
}

With this one, the sort works fine and the preffix search works with  
words without accent . However, when I try to search using "joã\*" it  
doesn't return any result, although it returns when I use "joa\*" and,  
when I search with two words, like "joao pes", it still returns  
cities beginning with "pes". It looks like it doesn't care about the  
analyzer when it is searching using the PreffixQuery.

The Jquery requisition is:

```
 				$.ajax({
					type: "GET",
					url: "http://localhost:9200/indice/cidade/_search",
					dataType: 'jsonp',
					data: {
						analyzer: "palavras",
						q : "nome:" + request.term + "*",
						sort: "nome"
 					},
					jsonpCallback : 'cidadesRetornadas'
				});

```

Which converts to this query string:

[http://localhost:9200/indice/cidade/\_search?callback=cidadesRetornadas&analyzer=palavras&q=nome%3Ajo\*&sort=nome](http://localhost:9200/indice/cidade/_search?callback=cidadesRetornadas&analyzer=palavras&q=nome%3Ajo*&sort=nome)

Regards  
Jorge

On 12 abr, 15:53, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> On Mon, 2010-04-12 at 10:49 -0700,Walendowrote:
> 
> > Fist of all, when I use "jo\*" as the query (preffix query), I expect  
> > no ocurrences like "Mata de São João", because it doesn't start with  
> > jo, it contains a word that starts with it instead.
> 
> Your text is being broken down into "terms" by the analyzer, where a  
> term corresponds roughly to a separate word.
> 
> The point of full text search is to search for individual words within  
> larger blocks of text.
> 
> However, if you want the "nome" field to be considered as a whole, then  
> you should use a custom analyzer with a 'keyword' tokenizer and a  
> 'lowercase' filter:[Analysis | Elasticsearch Guide [8.11] | Elastic](http://www.elasticsearch.com/docs/elasticsearch/index_modules/analysis/)
> 
> That way, ﻿"Dom Joaquim" would be considered as the single term "dom  
> joaquim", instead of it being broken down into "dom" ﻿and "joaquim", as  
> is happening now.
> 
> You can make this custom analyzer available to all indexes by adding  
> this to config/elasticsearch.yaml:
> 
> index :  
> analysis :  
> analyzer :  
> lower\_term: # this is your name for the analyzer  
> type : custom  
> tokenizer: keyword  
> filter: [lowercase]
> 
> Once you have done that, you can use the prefix query, eg:
> 
> { "query": { "prefix": { "nome": "jo"} } }
> 
> > And there are other cities, like João Pessoa, that aren't on the list,  
> > while Jordânia is.
> 
> Hmm, it looks like ES is using a simple sort rather than a proper  
> unicode collation. I've opened an issue  
> here: ﻿[Support unicode collations · Issue #130 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/issue/130)
> 
> hope this helps
> 
> ## clint
> 
> Web Announcements Limited is a company registered in England and Wales,  
> with company number 05608868, with registered address at 10 Arvon Road,  
> London, N5 1PR.

---

<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:** [April 30, 2010, 5:16pm UTC](https://discuss.elastic.co/t/query-no-working/2905/8 "2010-04-30T17:16:00Z")

</div>

Prefix and wildcard queries don't get analyzed. Open a feature request and I  
will enhance Lucene to do that if one wishes to.

By the way, in master (upcoming 0.7.0) I added the icu analysis plugin which  
provides much better unicode normalization and folding.

cheers,  
shay.banon

On Wed, Apr 28, 2010 at 4:25 PM, Walendo [jorge.walendowsky@gmail.com](mailto:jorge.walendowsky@gmail.com)wrote:

> Hi! After a little break, finally I could manage to go on with my  
> researches..
> 
> I created this Analyzer:
> 
> index :  
> analysis :  
> analyzer :  
> palavras :  
> type : custom  
> tokenizer : keyword  
> filter : [lowercase, asciifolding]
> 
> The mapping is:
> 
> {  
> "cidade" : {  
> "properties" : {  
> "codigo" : {"type" : "integer" , "store" : "yes"},  
> "nome" : {"type" : "string", "store" : "yes",  
> "index" : "analyzed",  
> "analyzer" : "palavras"},  
> "estado" : {"type" : "string", "store" :"yes"}  
> }  
> }  
> }
> 
> With this one, the sort works fine and the preffix search works with  
> words without accent . However, when I try to search using "joã\*" it  
> doesn't return any result, although it returns when I use "joa\*" and,  
> when I search with two words, like "joao pes", it still returns  
> cities beginning with "pes". It looks like it doesn't care about the  
> analyzer when it is searching using the PreffixQuery.
> 
> The Jquery requisition is:
> 
> ```
> $.ajax({
> type: "GET",
> url: "
> 
> ```
> 
> [http://localhost:9200/indice/cidade/\_search](http://localhost:9200/indice/cidade/_search)",  
> dataType: 'jsonp',  
> data: {  
> analyzer:  
> "palavras",  
> q : "nome:" +  
> request.term + "\*",  
> sort: "nome"  
> },  
> jsonpCallback :  
> 'cidadesRetornadas'  
> });
> 
> Which converts to this query string:
> 
> [http://localhost:9200/indice/cidade/\_search?callback=cidadesRetornadas&analyzer=palavras&q=nome%3Ajo\*&sort=nome](http://localhost:9200/indice/cidade/_search?callback=cidadesRetornadas&analyzer=palavras&q=nome%3Ajo*&sort=nome)
> 
> Regards  
> Jorge
> 
> On 12 abr, 15:53, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:
> 
> > On Mon, 2010-04-12 at 10:49 -0700,Walendowrote:
> > 
> > > Fist of all, when I use "jo\*" as the query (preffix query), I expect  
> > > no ocurrences like "Mata de São João", because it doesn't start with  
> > > jo, it contains a word that starts with it instead.
> > 
> > Your text is being broken down into "terms" by the analyzer, where a  
> > term corresponds roughly to a separate word.
> > 
> > The point of full text search is to search for individual words within  
> > larger blocks of text.
> > 
> > However, if you want the "nome" field to be considered as a whole, then  
> > you should use a custom analyzer with a 'keyword' tokenizer and a  
> > 'lowercase' filter:  
> > [Analysis | Elasticsearch Guide [8.11] | Elastic](http://www.elasticsearch.com/docs/elasticsearch/index_modules/analysis/)
> > 
> > That way, ﻿"Dom Joaquim" would be considered as the single term "dom  
> > joaquim", instead of it being broken down into "dom" ﻿and "joaquim", as  
> > is happening now.
> > 
> > You can make this custom analyzer available to all indexes by adding  
> > this to config/elasticsearch.yaml:
> > 
> > index :  
> > analysis :  
> > analyzer :  
> > lower\_term: # this is your name for the analyzer  
> > type : custom  
> > tokenizer: keyword  
> > filter: [lowercase]
> > 
> > Once you have done that, you can use the prefix query, eg:
> > 
> > { "query": { "prefix": { "nome": "jo"} } }
> > 
> > > And there are other cities, like João Pessoa, that aren't on the list,  
> > > while Jordânia is.
> > 
> > Hmm, it looks like ES is using a simple sort rather than a proper  
> > unicode collation. I've opened an issue  
> > here: ﻿[Support unicode collations · Issue #130 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/issue/130)
> > 
> > hope this helps
> > 
> > ## clint
> > 
> > Web Announcements Limited is a company registered in England and Wales,  
> > with company number 05608868, with registered address at 10 Arvon Road,  
> > London, N5 1PR.

---

<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, 4:24am UTC](https://discuss.elastic.co/t/query-no-working/2905/9 "2017-07-06T04:24:21Z")

</div>


