1
votes

I have an Elasticsearch index where my default analyzer is the snowball analyzer so I can get the stemming and now I need the ability to have synonyms on some of the fields as well as the benefit of the snowball analyzer to do stemming.

Is this possible and if so how?

As a test I tried to set a synonym filter on the snowball analiyzer, hoping that it would enable synonyms on all fields so I can test it but that didn't really work...

I created another analyzer for synonyms on my index with the WordNet synonym file.

If I am not clear please let me know and I'll try and update. Here is my current index settings.

"settings": {
            "index": {
                "analysis": {
                    "analyzer": {
                        "synonym": {
                            "filter": [
                                "synonym"
                            ],
                            "tokenizer": "whitespace"
                        },
                        "default": {
                            "language": "English",
                            "type": "snowball"
                        }
                    },
                    "filter": {
                        "synonym": {
                            "type": "synonym",
                            "synonyms_path": "/elasticsearch/wn_s.pl",
                            "format": "wordnet"
                        }
                    }
                }
            }
        }
    }
1

1 Answers

1
votes

You probably have to specify a custom analyzer for that, which uses the same tokenizer and filters as the snowball analyzer (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-snowball-analyzer.html). The add the synonym filter to it as well.

"analyzer": {
    "default": {
        "type": "custom",
        "filter": [
            "standard",
            "lowercase",
            "snowball",
            "synonym"
        ],
        "tokenizer": "standard"
    }
}

I haven't tried it and I'm not sure if you have to specify the snowball filter. If it doesn't work, try to specify the snowball filter as seen here: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-snowball-tokenfilter.html