Query no working


(Walendo) #1

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"]

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


(Shay Banon) #2

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

http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sorthttp://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:[\
=nome

On Sun, Apr 11, 2010 at 11:45 PM, Walendo jorge.walendowsky@gmail.comwrote:

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"]

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


(Walendo) #3

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 wrote:

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

http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sorthttp://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:[\
=nome

On Sun, Apr 11, 2010 at 11:45 PM, Walendo jorge.walendow...@gmail.comwrote:

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"]

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


(Clinton Gormley) #4

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 wrote:

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

http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sorthttp://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:[\
=nome

On Sun, Apr 11, 2010 at 11:45 PM, Walendo jorge.walendow...@gmail.comwrote:

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"]

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.


(Walendo) #5

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 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 wrote:

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

http://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sorthttp://localhost:9200/ig/cidade/_search?size=10&q=nome:jo*&sort:fields:[\
=nome

On Sun, Apr 11, 2010 at 11:45 PM, Walendo jorge.walendow...@gmail.comwrote:

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"]

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.


(Clinton Gormley) #6

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/

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: 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.


(Walendo) #7

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

Regards
Jorge

On 12 abr, 15:53, Clinton Gormley 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: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: 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.


(Shay Banon) #8

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.comwrote:

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

Regards
Jorge

On 12 abr, 15:53, Clinton Gormley 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:
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: 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.


(system) #9