# Snowball Analyzer and Java API

**URL:** <https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981>\
**Category:** Elasticsearch\
**Created:** [March 13, 2012, 3:09pm UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981 "2012-03-13T15:09:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thinusp](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@thinusp](https://discuss.elastic.co/u/thinusp)\
**Post date:** [March 13, 2012, 3:09pm UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/1 "2012-03-13T15:09:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![k4Rla](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@k4Rla](https://discuss.elastic.co/u/k4Rla)\
**Post date:** [March 13, 2012, 3:30pm UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/2 "2012-03-13T15:30:10Z")

</div>

Hi, i'm not sure, but if i understand u right, u speak about this  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](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  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](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

---

<div class="post-metadata">

**Author:** ![k4Rla](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@k4Rla](https://discuss.elastic.co/u/k4Rla)\
**Post date:** [March 13, 2012, 3:38pm UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/3 "2012-03-13T15:38:49Z")

</div>

u can alose define index and search analyzers  
[http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html](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

---

<div class="post-metadata">

**Author:** ![thinusp](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@thinusp](https://discuss.elastic.co/u/thinusp)\
**Post date:** [March 13, 2012, 3:59pm UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/4 "2012-03-13T15:59:13Z")

</div>

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! 😃 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](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

---

<div class="post-metadata">

**Author:** ![k4Rla](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@k4Rla](https://discuss.elastic.co/u/k4Rla)\
**Post date:** [March 13, 2012, 4:14pm UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/5 "2012-03-13T16:14:23Z")

</div>

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](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! 😃 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](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

---

<div class="post-metadata">

**Author:** ![k4Rla](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@k4Rla](https://discuss.elastic.co/u/k4Rla)\
**Post date:** [March 13, 2012, 4:17pm UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/6 "2012-03-13T16:17:13Z")

</div>

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

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

or this

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

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

---

<div class="post-metadata">

**Author:** ![Barsk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/barsk/32/13734_2.png) [@Barsk](https://discuss.elastic.co/u/Barsk)\
**Post date:** [March 14, 2012, 8:08am UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/7 "2012-03-14T08:08:51Z")

</div>

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

---

<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, 3:36am UTC](https://discuss.elastic.co/t/snowball-analyzer-and-java-api/6981/8 "2017-07-06T03:36:18Z")

</div>


