# Can't get snowball analyzer to work via Java

**URL:** <https://discuss.elastic.co/t/cant-get-snowball-analyzer-to-work-via-java/8794>\
**Category:** Elasticsearch\
**Created:** [August 21, 2012, 12:30am UTC](https://discuss.elastic.co/t/cant-get-snowball-analyzer-to-work-via-java/8794 "2012-08-21T00:30:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_5/32/1873_2.png) [@Jason\_5](https://discuss.elastic.co/u/Jason_5)\
**Post date:** [August 21, 2012, 12:30am UTC](https://discuss.elastic.co/t/cant-get-snowball-analyzer-to-work-via-java/8794/1 "2012-08-21T00:30:18Z")

</div>

Hey folks,

This is either a misconfiguration by me, or a misunderstanding (or both)  
but I'm struggling to get the snowball analyzer to work.

When I create my index(es) I am specifying the following settings:

ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()  
.startObject()  
.startObject("analysis")  
.startObject("analyzer")  
.startObject("custom")  
.field("tokenizer", "standard")  
.field("filter", new String[]{"standard", "lowercase",  
"snowball"})  
.endObject()  
.endObject()  
.startObject("filter")  
.startObject("snowball")  
.field("type", "snowball")  
.field("language", "English")  
.endObject()  
.endObject()  
.endObject()  
.endObject().string());

Then when I perform a search I am specifying the analyzer:

QueryBuilder query = queryString(queryString).analyzer("custom");

But it's not working (meaning, a search for the term "art" does not match  
documents with the word "arts"). I have NOT yet manually added the  
analyzer to the field definition in the mapping because I don't want to  
define a specific language for the field (I don't know ahead of time what  
language the content will be in.

I'm wondering if this is just the wrong approach. Do I HAVE to nominate a  
specific analyser for a single field?, and if so how would one go about  
supporting multiple languages? (multiple indexes I guess?)

What I'm really looking for is a full working example of a "sensible"  
configuration for ElasticSearch which will give me all the basic free text  
search features, like stemming. Although the "a la carte" approach is  
great, it would be nice if the default implementation served the most  
predominant use case(s).

Thanks!

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 21, 2012, 1:51am UTC](https://discuss.elastic.co/t/cant-get-snowball-analyzer-to-work-via-java/8794/2 "2012-08-21T01:51:16Z")

</div>

I think that you have indexed arts with a default analyzer. So, when you search for art, you can't find it.  
Specifying analyzer at search time means that your searched string is analyzed before being compared with the index. So Art is analyzed to art.

To make it work, you should apply your analyzer at index time. So, you need to define it on your field.

If you have multiple analyzers to apply to a field, I recommand to use the cool multifield feature.  
[http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)

## HTH

David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 21 août 2012 à 02:30, Jason [jason.polites@gmail.com](mailto:jason.polites@gmail.com) a écrit :

Hey folks,

This is either a misconfiguration by me, or a misunderstanding (or both) but I'm struggling to get the snowball analyzer to work.

When I create my index(es) I am specifying the following settings:

ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()  
.startObject()  
.startObject("analysis")  
.startObject("analyzer")  
.startObject("custom")  
.field("tokenizer", "standard")  
.field("filter", new String[]{"standard", "lowercase", "snowball"})  
.endObject()  
.endObject()  
.startObject("filter")  
.startObject("snowball")  
.field("type", "snowball")  
.field("language", "English")  
.endObject()  
.endObject()  
.endObject()  
.endObject().string());

Then when I perform a search I am specifying the analyzer:

QueryBuilder query = queryString(queryString).analyzer("custom");

But it's not working (meaning, a search for the term "art" does not match documents with the word "arts"). I have NOT yet manually added the analyzer to the field definition in the mapping because I don't want to define a specific language for the field (I don't know ahead of time what language the content will be in.

I'm wondering if this is just the wrong approach. Do I HAVE to nominate a specific analyser for a single field?, and if so how would one go about supporting multiple languages? (multiple indexes I guess?)

What I'm really looking for is a full working example of a "sensible" configuration for ElasticSearch which will give me all the basic free text search features, like stemming. Although the "a la carte" approach is great, it would be nice if the default implementation served the most predominant use case(s).

Thanks!

--

--

---

<div class="post-metadata">

**Author:** ![Jason\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_5/32/1873_2.png) [@Jason\_5](https://discuss.elastic.co/u/Jason_5)\
**Post date:** [August 30, 2012, 3:16am UTC](https://discuss.elastic.co/t/cant-get-snowball-analyzer-to-work-via-java/8794/3 "2012-08-30T03:16:42Z")

</div>

Hi David,

Sorry for the late reply.. I was out of town... just wanted to say thanks!

- Jason.

On Monday, August 20, 2012 6:51:16 PM UTC-7, David Pilato wrote:

> I think that you have indexed arts with a default analyzer. So, when you  
> search for art, you can't find it.  
> Specifying analyzer at search time means that your searched string is  
> analyzed before being compared with the index. So Art is analyzed to art.
> 
> To make it work, you should apply your analyzer at index time. So, you  
> need to define it on your field.
> 
> If you have multiple analyzers to apply to a field, I recommand to use the  
> cool multifield feature.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)
> 
> ## HTH
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 21 août 2012 à 02:30, Jason \<[jason....@gmail.com](mailto:jason....@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hey folks,
> 
> This is either a misconfiguration by me, or a misunderstanding (or both)  
> but I'm struggling to get the snowball analyzer to work.
> 
> When I create my index(es) I am specifying the following settings:
> 
> ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()  
> .startObject()  
> .startObject("analysis")  
> .startObject("analyzer")  
> .startObject("custom")  
> .field("tokenizer", "standard")  
> .field("filter", new String{"standard", "lowercase",  
> "snowball"})  
> .endObject()  
> .endObject()  
> .startObject("filter")  
> .startObject("snowball")  
> .field("type", "snowball")  
> .field("language", "English")  
> .endObject()  
> .endObject()  
> .endObject()  
> .endObject().string());
> 
> Then when I perform a search I am specifying the analyzer:
> 
> QueryBuilder query = queryString(queryString).analyzer("custom");
> 
> But it's not working (meaning, a search for the term "art" does not match  
> documents with the word "arts"). I have NOT yet manually added the  
> analyzer to the field definition in the mapping because I don't want to  
> define a specific language for the field (I don't know ahead of time what  
> language the content will be in.
> 
> I'm wondering if this is just the wrong approach. Do I HAVE to nominate a  
> specific analyser for a single field?, and if so how would one go about  
> supporting multiple languages? (multiple indexes I guess?)
> 
> What I'm really looking for is a full working example of a "sensible"  
> configuration for Elasticsearch which will give me all the basic free text  
> search features, like stemming. Although the "a la carte" approach is  
> great, it would be nice if the default implementation served the most  
> predominant use case(s).
> 
> Thanks!
> 
> --

--

---

<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:14am UTC](https://discuss.elastic.co/t/cant-get-snowball-analyzer-to-work-via-java/8794/4 "2017-07-06T03:14:39Z")

</div>


