diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java index f077abb89f0..6cb4bac8c55 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.analysis; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.component.CloseableComponent; import org.elasticsearch.common.inject.Inject; @@ -86,7 +87,18 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable Map analyzers = newHashMap(); for (AnalyzerProvider analyzerFactory : analyzerProviders.values()) { - analyzers.put(analyzerFactory.name(), new NamedAnalyzer(analyzerFactory.name(), analyzerFactory.scope(), analyzerFactory.get())); + NamedAnalyzer analyzer = new NamedAnalyzer(analyzerFactory.name(), analyzerFactory.scope(), analyzerFactory.get()); + analyzers.put(analyzerFactory.name(), analyzer); + String strAliases = indexSettings.get("index.analysis.analyzer." + analyzerFactory.name() + ".alias"); + if (strAliases != null) { + for (String alias : Strings.commaDelimitedListToStringArray(strAliases)) { + analyzers.put(alias, analyzer); + } + } + String[] aliases = indexSettings.getAsArray("index.analysis.analyzer." + analyzerFactory.name() + ".alias"); + for (String alias : aliases) { + analyzers.put(alias, analyzer); + } } this.analyzers = ImmutableMap.copyOf(analyzers); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 23a54f83171..236d07cee96 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.lucene.analysis.HTMLStripCharFilter; @@ -77,5 +78,9 @@ public class AnalysisModuleTests { html = (HtmlStripCharFilterFactory) custom2.charFilters()[1]; assertThat(html.readAheadLimit(), equalTo(1024)); + + // verify aliases + analyzer = analysisService.analyzer("alias1").analyzer(); + assertThat(analyzer, instanceOf(StandardAnalyzer.class)); } } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.json index 1e8d08bd83f..66f24fab1f1 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.json +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.json @@ -25,10 +25,12 @@ }, "analyzer" : { "standard" : { + "alias" : "alias1,alias2", "type" : "standard", "stopwords" : ["test1", "test2", "test3"] }, "custom1" : { + "alias" : ["alias4", "alias5"], "tokenizer" : "standard", "filter" : ["stop", "stop2"] }, diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.yml b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.yml index 5a553e5f44b..ec8acfddf4d 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.yml +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/test1.yml @@ -17,9 +17,11 @@ index : stopwords : [stop2-1, stop2-2] analyzer : standard : + alias: alias1,alias2 type : standard stopwords : [test1, test2, test3] custom1 : + alias : [alias4, alias5] tokenizer : standard filter : [stop, stop2] custom2 :