The camel-case `nGram` and `edgeNGram` filter names were deprecated in 6. We currently throw errors on new indices when they are used. However these errors are currently only thrown for pre-configured filters, adding them as custom filters doesn't trigger the warning and error. This change adds the appropriate deprecation warnings for `nGram` and `edgeNGram` respectively on version 7 indices. Relates #50360
This commit is contained in:
parent
339d10c16f
commit
6258d25458
|
@ -118,9 +118,11 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.NodeEnvironment;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.analysis.AnalyzerProvider;
|
||||
import org.elasticsearch.index.analysis.CharFilterFactory;
|
||||
import org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory;
|
||||
|
@ -242,7 +244,12 @@ public class CommonAnalysisPlugin extends Plugin implements AnalysisPlugin, Scri
|
|||
filters.put("dictionary_decompounder", requiresAnalysisSettings(DictionaryCompoundWordTokenFilterFactory::new));
|
||||
filters.put("dutch_stem", DutchStemTokenFilterFactory::new);
|
||||
filters.put("edge_ngram", EdgeNGramTokenFilterFactory::new);
|
||||
filters.put("edgeNGram", EdgeNGramTokenFilterFactory::new);
|
||||
filters.put("edgeNGram", (IndexSettings indexSettings, Environment environment, String name, Settings settings) -> {
|
||||
deprecationLogger.deprecatedAndMaybeLog("edgeNGram_deprecation",
|
||||
"The [edgeNGram] token filter name is deprecated and will be removed in a future version. "
|
||||
+ "Please change the filter name to [edge_ngram] instead.");
|
||||
return new EdgeNGramTokenFilterFactory(indexSettings, environment, name, settings);
|
||||
});
|
||||
filters.put("elision", requiresAnalysisSettings(ElisionTokenFilterFactory::new));
|
||||
filters.put("fingerprint", FingerprintTokenFilterFactory::new);
|
||||
filters.put("flatten_graph", FlattenGraphTokenFilterFactory::new);
|
||||
|
@ -262,7 +269,12 @@ public class CommonAnalysisPlugin extends Plugin implements AnalysisPlugin, Scri
|
|||
filters.put("min_hash", MinHashTokenFilterFactory::new);
|
||||
filters.put("multiplexer", MultiplexerTokenFilterFactory::new);
|
||||
filters.put("ngram", NGramTokenFilterFactory::new);
|
||||
filters.put("nGram", NGramTokenFilterFactory::new);
|
||||
filters.put("nGram", (IndexSettings indexSettings, Environment environment, String name, Settings settings) -> {
|
||||
deprecationLogger.deprecatedAndMaybeLog("nGram_deprecation",
|
||||
"The [nGram] token filter name is deprecated and will be removed in a future version. "
|
||||
+ "Please change the filter name to [ngram] instead.");
|
||||
return new NGramTokenFilterFactory(indexSettings, environment, name, settings);
|
||||
});
|
||||
filters.put("pattern_capture", requiresAnalysisSettings(PatternCaptureGroupTokenFilterFactory::new));
|
||||
filters.put("pattern_replace", requiresAnalysisSettings(PatternReplaceTokenFilterFactory::new));
|
||||
filters.put("persian_normalization", PersianNormalizationFilterFactory::new);
|
||||
|
|
|
@ -169,4 +169,43 @@ public class CommonAnalysisPluginTests extends ESTestCase {
|
|||
"replace it with a custom analyzer using [standard] tokenizer and [html_strip] char_filter, plus [lowercase] filter");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the deprecated "nGram" filter logs a warning when the filter is used as a custom filter
|
||||
*/
|
||||
public void testnGramFilterInCustomAnalyzerDeprecationError() throws IOException {
|
||||
final Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED,
|
||||
VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.CURRENT))
|
||||
.put("index.analysis.analyzer.custom_analyzer.type", "custom")
|
||||
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard")
|
||||
.putList("index.analysis.analyzer.custom_analyzer.filter", "my_ngram")
|
||||
.put("index.analysis.filter.my_ngram.type", "nGram")
|
||||
.build();
|
||||
|
||||
final CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin();
|
||||
|
||||
createTestAnalysis(IndexSettingsModule.newIndexSettings("index", settings), settings, commonAnalysisPlugin);
|
||||
assertWarnings("The [nGram] token filter name is deprecated and will be removed in a future version. "
|
||||
+ "Please change the filter name to [ngram] instead.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the deprecated "edgeNGram" filter logs a warning when the filter is used as a custom filter
|
||||
*/
|
||||
public void testEdgeNGramFilterInCustomAnalyzerDeprecationError() throws IOException {
|
||||
final Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED,
|
||||
VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.CURRENT))
|
||||
.put("index.analysis.analyzer.custom_analyzer.type", "custom")
|
||||
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard")
|
||||
.putList("index.analysis.analyzer.custom_analyzer.filter", "my_ngram")
|
||||
.put("index.analysis.filter.my_ngram.type", "edgeNGram")
|
||||
.build();
|
||||
final CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin();
|
||||
|
||||
createTestAnalysis(IndexSettingsModule.newIndexSettings("index", settings), settings, commonAnalysisPlugin);
|
||||
assertWarnings("The [edgeNGram] token filter name is deprecated and will be removed in a future version. "
|
||||
+ "Please change the filter name to [edge_ngram] instead.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue