Snowball Analyzer and Java API


(thinusp) #1

I'm having a big struggle to get a Snowball Analyser working on my index...
I'm trying to use the Java API to set the relevant settings/mapping not
even sure which it is any more.

From the website I gathered that I want to set something like this:

{
"index" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"type" : "snowball",
"language" : "English"
}
}
}
}
}

... though how exactly and where I do not know. Is this part of the
mapping or the setting of an index? Do I have to define "my_analyzer"?
Surely snowball is popular enough that it is included in the Elasticsearch
project?

I've tried adding the mapping (constructed as a Json object through the
XContentBuilder) to the CreateIndexRequestBuilder object that is linked to
my Index, thought the setSettings() option, but no luck there.

Any help with in this regard would be greatly appreciated.

  • Thinus

(k4Rla) #2

Hi, i'm not sure, but if i understand u right, u speak about this
http://www.elasticsearch.org/guide/reference/mapping/analyzer-field.html,
so u can also define u r analyzer in your search query, if this query
supports this definning, for example
http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html,
looks like

"query" : {
"queryString" : {
"default_field" : "message",
"query" : "elasticsearch",
"analyzer" : "my_analyzer"
}
},

On Tuesday, March 13, 2012 7:09:17 PM UTC+4, Thinus Prinsloo wrote:

I'm having a big struggle to get a Snowball Analyser working on my
index... I'm trying to use the Java API to set the relevant
settings/mapping not even sure which it is any more.

From the website I gathered that I want to set something like this:

{
"index" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"type" : "snowball",
"language" : "English"
}
}
}
}
}

... though how exactly and where I do not know. Is this part of the
mapping or the setting of an index? Do I have to define "my_analyzer"?
Surely snowball is popular enough that it is included in the Elasticsearch
project?

I've tried adding the mapping (constructed as a Json object through the
XContentBuilder) to the CreateIndexRequestBuilder object that is linked to
my Index, thought the setSettings() option, but no luck there.

Any help with in this regard would be greatly appreciated.

  • Thinus

(k4Rla) #3

u can alose define index and search analyzers
http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html
index calls when u create an index, search calls when u do a search


(thinusp) #4

Thanks k4RIa,

I managed (I think) to get it working by setting the analyzer property
during the index create process (as you suggested) with the following Java
code:
mapping_content.field("Text").startObject().field("type",
"string").field("store", "no").field("index", "analyzed").field("analyzer",
"snowball").endObject();

That seems simple enough! :smiley: Now, not entirely sure if it's actually
working, or just playing along at the moment. What I do need to figure out
is how to set up a query to correctly query data that's been analyzed with
the snowball analyzer.

Thanks again.

On Tuesday, 13 March 2012 17:38:49 UTC+2, k4Rla wrote:

u can alose define index and search analyzers
http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html

index calls when u create an index, search calls when u do a search


(k4Rla) #5

for example u can put two documents in your index with values 'automats'
and 'automatical', and then send a query 'automatic', if you get both
results, it's apparently works. More words for test u can find here
http://snowball.tartarus.org/demo.php

On Tuesday, March 13, 2012 7:59:13 PM UTC+4, Thinus Prinsloo wrote:

Thanks k4RIa,

I managed (I think) to get it working by setting the analyzer property
during the index create process (as you suggested) with the following Java
code:
mapping_content.field("Text").startObject().field("type",
"string").field("store", "no").field("index", "analyzed").field("analyzer",
"snowball").endObject();

That seems simple enough! :smiley: Now, not entirely sure if it's actually
working, or just playing along at the moment. What I do need to figure out
is how to set up a query to correctly query data that's been analyzed with
the snowball analyzer.

Thanks again.

On Tuesday, 13 March 2012 17:38:49 UTC+2, k4Rla wrote:

u can alose define index and search analyzers
http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html

index calls when u create an index, search calls when u do a search


(k4Rla) #6

Unfortunately, i dont know Java (but i really will :D), but to get results
u can help this
http://www.elasticsearch.org/guide/reference/query-dsl/prefix-query.html
or this
http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html

On Tuesday, March 13, 2012 7:09:17 PM UTC+4, Thinus Prinsloo wrote:

I'm having a big struggle to get a Snowball Analyser working on my
index... I'm trying to use the Java API to set the relevant
settings/mapping not even sure which it is any more.

From the website I gathered that I want to set something like this:

{
"index" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"type" : "snowball",
"language" : "English"
}
}
}
}
}

... though how exactly and where I do not know. Is this part of the
mapping or the setting of an index? Do I have to define "my_analyzer"?
Surely snowball is popular enough that it is included in the Elasticsearch
project?

I've tried adding the mapping (constructed as a Json object through the
XContentBuilder) to the CreateIndexRequestBuilder object that is linked to
my Index, thought the setSettings() option, but no luck there.

Any help with in this regard would be greatly appreciated.

  • Thinus

(Barsk) #7

Thinus Prinsloo skrev 2012-03-13 16:09:

I'm having a big struggle to get a Snowball Analyser working on my
index... I'm trying to use the Java API to set the relevant
settings/mapping not even sure which it is any more.
Firstly, the standard analyzer is for the english language. So you do
not need to define it, it is called for by "standard".
http://www.elasticsearch.org/guide/reference/index-modules/analysis/standard-analyzer.html

The documentation of the Java API could certainly improve IMHO. However,
I sorted out what I wanted to do by looking in the test code that is
part of the source (https://github.com/elasticsearch/elasticsearch). I
am sure that if you browse through there you will find solutions that
can be copied directly into your code.

I haven't been using mapping via the API directly myself so I cannot
help with specific code samples. I setup mapping by putting the index
definitions in config/elasticsearch.yml and the mappings in

config/mappings//.json
or if it is a general type mapping that can be used cross several indexes:
config/mappings/_default/.json

For example config/elasticsearch.yml:

index :
number_of_shards : 1
number_of_replicas : 0

 analysis :
     analyzer :
        sweAnalyzer :
             type: swedish

config/mappings/_default/card.json:

{
"card" : {
"properties" : {
"imageId" : {"type" : "integer"},
"text" : {"type" : "string", "analyzer" : "sweAnalyzer"}
}
}
}


(system) #8