Snowball Analyzer and Java API

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

Hi, i'm not sure, but if i understand u right, u speak about this
Elasticsearch Platform — Find real-time answers at scale | Elastic,
so u can also define u r analyzer in your search query, if this query
supports this definning, for example
Elasticsearch Platform — Find real-time answers at scale | Elastic,
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

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

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
Elasticsearch Platform — Find real-time answers at scale | Elastic

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

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
Elasticsearch Platform — Find real-time answers at scale | Elastic

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

Unfortunately, i dont know Java (but i really will :D), but to get results
u can help this

or this

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

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".
Elasticsearch Platform — Find real-time answers at scale | Elastic

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 (GitHub - elastic/elasticsearch: Free and Open, Distributed, RESTful Search Engine). 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"}
}
}
}