# How to set the anlyzer?

**URL:** <https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970>\
**Category:** Elasticsearch\
**Created:** [May 25, 2010, 7:24pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970 "2010-05-25T19:24:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [May 25, 2010, 7:24pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/1 "2010-05-25T19:24:11Z")

</div>

My lucene app (which I am converting to ElasticSearch) uses org.apache.lucene.analysis.snowball.SnowballAnalyzer as its analyzer. I like it for the stemming abilities. How can I get support for this (or another analyzer) in ElasticSearch? Thanks.

I am currently on ElasticSearch 0.7.1.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 26, 2010, 6:28am UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/2 "2010-05-26T06:28:47Z")

</div>

[http://www.elasticsearch.com/docs/elasticsearch/index\_modules/analysis/](http://www.elasticsearch.com/docs/elasticsearch/index_modules/analysis/)

On Tue, May 25, 2010 at 10:24 PM, John Chang [jchangkihtest2@gmail.com](mailto:jchangkihtest2@gmail.com)wrote:

> My lucene app (which I am converting to Elasticsearch) uses  
> org.apache.lucene.analysis.snowball.SnowballAnalyzer as its analyzer. I  
> like it for the stemming abilities. How can I get support for this (or  
> another analyzer) in Elasticsearch? Thanks.
> 
> ## I am currently on Elasticsearch 0.7.1.
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-set-the-anlyzer-tp842952p842952.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-set-the-anlyzer-tp842952p842952.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [May 26, 2010, 9:20pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/3 "2010-05-26T21:20:24Z")

</div>

I looked in the org.elasticsearch.index.analysis directory and could not find any analyzer privider for the SnowballAnalyzer. So, using the BrazilianAnalyzerProvider as an example, I tried to create my own, but I keep getting this  
error upon startup:  
"1) Could not find a suitable constructor in com.kiha.server.services.index.KihaSnowballAnalyzer. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private."

However, my class does have one constructor with an @Inject annotation. This is what I did:

I tried adding this to my elasticsearch.json:  
index:  
analysis:  
analyzer:  
standard:  
type: com.mycompany.server.services.index.MyCompanySnowballAnalyzerProvider

I put com.mycompany.server.services.index.MyCompanySnowballAnalyzerProvider into a jar in the ./lib directory. The class has this constructor:

```
@Inject public MyCompanySnowballAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettings, name);
    analyzer = new SnowballAnalyzer(Version.LUCENE_CURRENT, "English");
}

```

The class extends AbstractAnalyzerProvider:  
public class MyCompanySnowballAnalyzerProvider extends AbstractAnalyzerProvider

---

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [May 26, 2010, 9:23pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/4 "2010-05-26T21:23:04Z")

</div>

Typo: in the above message, I meant to replace "kiha" with "mycompany" throughout, but missed some places. So "Could not find a suitable constructor in com.kiha.server.services.index.KihaSnowballAnalyzer." should be read as "Could not find a suitable constructor in com.mycompany.server.services.index.MyCompanySnowballAnalyzerProvider." in order to correspond to the rest of my post. Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 28, 2010, 10:25pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/5 "2010-05-28T22:25:57Z")

</div>

This should work, strange. You get an exception for  
com.kiha.server.services.index.KihaSnowballAnalyzer,  
while I would expect you would get the exception for  
com.kiha.server.services.index.KihaSnowballAnalyzerProvider  
(note the Provider at the end). Which one are you getting again?

On Thu, May 27, 2010 at 12:23 AM, John Chang [jchangkihtest2@gmail.com](mailto:jchangkihtest2@gmail.com)wrote:

> ## Typo: in the above message, I meant to replace "kiha" with "mycompany" throughout, but missed some places. So "Could not find a suitable constructor in com.kiha.server.services.index.KihaSnowballAnalyzer." should be read as "Could not find a suitable constructor in com.mycompany.server.services.index.MyCompanySnowballAnalyzerProvider." in order to correspond to the rest of my post. Thanks.
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-set-the-anlyzer-tp842952p846196.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-set-the-anlyzer-tp842952p846196.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [June 1, 2010, 10:29pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/6 "2010-06-01T22:29:45Z")

</div>

I am getting an exception from com.kiha.server.services.index.KihaSnowballAnalyzer. Although perhaps oddly named, this class IS an extension of AbstractAnalyzerProvider. It is declared as:

public class KihaSnowballAnalyzer extends AbstractAnalyzerProvider

I do not have a class named KihaSnowballAnalyzerProvider.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 1, 2010, 10:43pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/7 "2010-06-01T22:43:07Z")

</div>

Can you write a quick test case and I will check why this happens?

On Wed, Jun 2, 2010 at 1:29 AM, John Chang [jchangkihtest2@gmail.com](mailto:jchangkihtest2@gmail.com) wrote:

> I am getting an exception from  
> com.kiha.server.services.index.KihaSnowballAnalyzer. Although perhaps  
> oddly  
> named, this class IS an extension of AbstractAnalyzerProvider. It is  
> declared as:
> 
> public class KihaSnowballAnalyzer extends  
> AbstractAnalyzerProvider
> 
> ## I do not have a class named KihaSnowballAnalyzerProvider.
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-set-the-anlyzer-tp842952p863060.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-set-the-anlyzer-tp842952p863060.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [June 1, 2010, 11:08pm UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/8 "2010-06-01T23:08:26Z")

</div>

I can't write a test case in terms of a JUnit to repro the issue, as I can't get the server to start up without error. The test is simply to start up the server and look for errors. If you wanted to repro it, all I can think of is to try to run my class and config. To repro:

1. Use 0.7.1 (no particular reason I'm not on latest; just that it changes often, I can try with the latest if you advise)

2. Add this to your elasticsearch.yml:  
index:  
analysis:  
analyzer:  
standard:  
type: com.kiha.server.services.index.KihaSnowballAnalyzer

3. Compile this class and put it in your classpath. Note that it is modeled on the BrazilianAnalyzer I found. Note also that to get it to compile, you need lucene-snowball-3.0.0-sources.jar.

Thanks for your time.

package com.kiha.server.services.index;

import com.google.common.collect.ImmutableSet;  
import com.google.common.collect.Iterators;  
import com.google.inject.Inject;  
import com.google.inject.assistedinject.Assisted;  
//import org.apache.lucene.analysis.br.BrazilianAnalyzer;  
import org.apache.lucene.analysis.snowball.SnowballAnalyzer;  
import org.apache.lucene.util.Version;  
import org.elasticsearch.index.Index;  
import org.elasticsearch.index.analysis.AbstractAnalyzerProvider;  
import org.elasticsearch.index.settings.IndexSettings;  
import org.elasticsearch.util.settings.Settings;

import java.util.Set;

public class KihaSnowballAnalyzer extends AbstractAnalyzerProvider {

```
private final Set<?> stopWords;

private final Set<?> stemExclusion;

private final SnowballAnalyzer analyzer;

@Inject public KihaSnowballAnalyzer(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettings, name);
    String[] stopWords = settings.getAsArray("stopwords");
    if (stopWords.length > 0) {
        this.stopWords = ImmutableSet.copyOf(Iterators.forArray(stopWords));
    } else {
        this.stopWords = ImmutableSet.copyOf(Iterators.forArray());
        //this.stopWords = BrazilianAnalyzer.getDefaultStopSet();
    }

    String[] stemExclusion = settings.getAsArray("stem_exclusion");
    if (stemExclusion.length > 0) {
        this.stemExclusion = ImmutableSet.copyOf(Iterators.forArray(stemExclusion));
    } else {
        this.stemExclusion = ImmutableSet.of();
    }
    analyzer = new SnowballAnalyzer(Version.LUCENE_CURRENT, "English");
}

@Override public SnowballAnalyzer get() {
    return this.analyzer;
}

```

}

---

<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, 4:23am UTC](https://discuss.elastic.co/t/how-to-set-the-anlyzer/2970/9 "2017-07-06T04:23:38Z")

</div>


