diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java index 24caeceb88f..56548c66b53 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.analysis; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.ImmutableSettings; @@ -39,12 +40,6 @@ import static org.elasticsearch.common.collect.Lists.*; */ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider { - private final TokenizerFactory tokenizerFactory; - - private final CharFilterFactory[] charFilterFactories; - - private final TokenFilterFactory[] tokenFilterFactories; - private final CustomAnalyzer customAnalyzer; @Inject public CustomAnalyzerProvider(Index index, @@ -60,20 +55,32 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider charFilters = newArrayList(); String[] charFilterNames = settings.getAsArray("char_filter"); for (String charFilterName : charFilterNames) { CharFilterFactoryFactory charFilterFactoryFactory = charFilterFactories.get(charFilterName); if (charFilterFactoryFactory == null) { - throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find char filter under name [" + charFilterName + "]"); + charFilterFactoryFactory = charFilterFactories.get(Strings.toCamelCase(charFilterName)); + if (charFilterFactoryFactory == null) { + charFilterFactoryFactory = charFilterFactories.get(Strings.toUnderscoreCase(charFilterName)); + if (charFilterFactoryFactory == null) { + throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find char filter under name [" + charFilterName + "]"); + } + } } Settings charFilterSettings = indexSettings.getGroups("index.analysis.char_filter").get(charFilterName); if (charFilterSettings == null) { @@ -81,14 +88,20 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider tokenFilters = newArrayList(); String[] tokenFilterNames = settings.getAsArray("filter"); for (String tokenFilterName : tokenFilterNames) { TokenFilterFactoryFactory tokenFilterFactoryFactory = tokenFilterFactories.get(tokenFilterName); if (tokenFilterFactoryFactory == null) { - throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find token filter under name [" + tokenFilterName + "]"); + tokenFilterFactoryFactory = tokenFilterFactories.get(Strings.toCamelCase(tokenFilterName)); + if (tokenFilterFactoryFactory == null) { + tokenFilterFactoryFactory = tokenFilterFactories.get(Strings.toUnderscoreCase(tokenFilterName)); + if (tokenFilterFactoryFactory == null) { + throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find token filter under name [" + tokenFilterName + "]"); + } + } } Settings tokenFilterSettings = indexSettings.getGroups("index.analysis.filter").get(tokenFilterName); if (tokenFilterSettings == null) { @@ -96,9 +109,9 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider