diff --git a/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java b/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java index 397c1b2c922b0..40239cbf38567 100644 --- a/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java +++ b/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java @@ -50,7 +50,6 @@ public class ArabicAnalyzerProvider extends AbstractIndexAnalyzerProvider analyze(Settings settings, String analyzerName, String text) throws IOException { diff --git a/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java b/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java index 5a0cf81cc379e..2319b825892ac 100644 --- a/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java +++ b/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java @@ -46,7 +46,6 @@ public PolishAnalyzerProvider(IndexSettings indexSettings, Environment environme super(indexSettings, name, settings); analyzer = new PolishAnalyzer(PolishAnalyzer.getDefaultStopSet()); - analyzer.setVersion(version); } @Override diff --git a/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java b/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java index b6bb76e0c9893..9beced7d465a6 100644 --- a/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java +++ b/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java @@ -48,7 +48,6 @@ public UkrainianAnalyzerProvider(IndexSettings indexSettings, Environment env, S Analysis.parseStopWords(env, settings, UkrainianMorfologikAnalyzer.getDefaultStopSet()), Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) ); - analyzer.setVersion(version); } @Override diff --git a/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java b/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java index fadd6be733637..eb279a9127dc4 100644 --- a/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java +++ b/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java @@ -33,7 +33,6 @@ package org.opensearch.index.analysis; import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.util.Version; import org.opensearch.common.settings.Settings; import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.IndexSettings; @@ -42,8 +41,6 @@ public abstract class AbstractIndexAnalyzerProvider extends private final String name; - protected final Version version; - /** * Constructs a new analyzer component, with the index name and its settings and the analyzer name. * @@ -53,7 +50,7 @@ public abstract class AbstractIndexAnalyzerProvider extends public AbstractIndexAnalyzerProvider(IndexSettings indexSettings, String name, Settings settings) { super(indexSettings); this.name = name; - this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); + Analysis.parseAndDeprecateAnalysisVersion(name, settings); } /** diff --git a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java index f3222753fabb5..2f91c19c1b78d 100644 --- a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java +++ b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java @@ -32,7 +32,6 @@ package org.opensearch.index.analysis; -import org.apache.lucene.util.Version; import org.opensearch.common.settings.Settings; import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.IndexSettings; @@ -41,20 +40,14 @@ public abstract class AbstractTokenFilterFactory extends AbstractIndexComponent private final String name; - protected final Version version; - public AbstractTokenFilterFactory(IndexSettings indexSettings, String name, Settings settings) { super(indexSettings); this.name = name; - this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); + Analysis.parseAndDeprecateAnalysisVersion(name, settings); } @Override public String name() { return this.name; } - - public final Version version() { - return version; - } } diff --git a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java index 49c18d5c1d704..825f8241d3e2e 100644 --- a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java +++ b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java @@ -32,25 +32,19 @@ package org.opensearch.index.analysis; -import org.apache.lucene.util.Version; import org.opensearch.common.settings.Settings; import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.IndexSettings; public abstract class AbstractTokenizerFactory extends AbstractIndexComponent implements TokenizerFactory { - protected final Version version; private final String name; public AbstractTokenizerFactory(IndexSettings indexSettings, Settings settings, String name) { super(indexSettings); - this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); + Analysis.parseAndDeprecateAnalysisVersion(name, settings); this.name = name; } - public final Version version() { - return version; - } - @Override public String name() { return name; diff --git a/server/src/main/java/org/opensearch/index/analysis/Analysis.java b/server/src/main/java/org/opensearch/index/analysis/Analysis.java index 38c5beaf9d80e..8d780bdd4483e 100644 --- a/server/src/main/java/org/opensearch/index/analysis/Analysis.java +++ b/server/src/main/java/org/opensearch/index/analysis/Analysis.java @@ -32,7 +32,6 @@ package org.opensearch.index.analysis; -import org.apache.logging.log4j.Logger; import org.apache.lucene.analysis.CharArraySet; import org.apache.lucene.analysis.ar.ArabicAnalyzer; import org.apache.lucene.analysis.bg.BulgarianAnalyzer; @@ -68,9 +67,8 @@ import org.apache.lucene.analysis.sv.SwedishAnalyzer; import org.apache.lucene.analysis.th.ThaiAnalyzer; import org.apache.lucene.analysis.tr.TurkishAnalyzer; -import org.apache.lucene.util.Version; import org.opensearch.common.Strings; -import org.opensearch.common.lucene.Lucene; +import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.settings.Settings; import org.opensearch.env.Environment; @@ -93,19 +91,18 @@ public class Analysis { - public static Version parseAnalysisVersion(Settings indexSettings, Settings settings, Logger logger) { + private static DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(Analysis.class); + + /** version is deprecated and will be removed; this method parses explicit version and issues a deprecation warning */ + public static void parseAndDeprecateAnalysisVersion(String name, Settings settings) { // check for explicit version on the specific analyzer component String sVersion = settings.get("version"); if (sVersion != null) { - return Lucene.parseVersion(sVersion, Version.LATEST, logger); - } - // check for explicit version on the index itself as default for all analysis components - sVersion = indexSettings.get("index.analysis.version"); - if (sVersion != null) { - return Lucene.parseVersion(sVersion, Version.LATEST, logger); + DEPRECATION_LOGGER.deprecate( + "analyzer.version", + "Setting [version] on analysis [" + name + "] is deprecated, no longer used, and will be removed in a future version." + ); } - // resolve the analysis version based on the version the index was created with - return org.opensearch.Version.indexCreated(indexSettings).luceneVersion; } public static CharArraySet parseStemExclusion(Settings settings, CharArraySet defaultStemExclusion) { diff --git a/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java b/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java index aa3343f69b137..d2c5384153bd2 100644 --- a/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java +++ b/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java @@ -60,17 +60,13 @@ public class PreBuiltAnalyzerProviderFactory extends PreConfiguredAnalysisCompon PreBuiltAnalyzerProviderFactory(String name, PreBuiltAnalyzers preBuiltAnalyzer) { super(name, new PreBuiltAnalyzersDelegateCache(name, preBuiltAnalyzer)); this.create = preBuiltAnalyzer::getAnalyzer; - Analyzer analyzer = preBuiltAnalyzer.getAnalyzer(Version.CURRENT); - analyzer.setVersion(Version.CURRENT.luceneVersion); - current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer); + current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, preBuiltAnalyzer.getAnalyzer(Version.CURRENT)); } public PreBuiltAnalyzerProviderFactory(String name, PreBuiltCacheFactory.CachingStrategy cache, Supplier create) { super(name, cache); this.create = version -> create.get(); - Analyzer analyzer = create.get(); - analyzer.setVersion(Version.CURRENT.luceneVersion); - this.current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer); + this.current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, create.get()); } @Override @@ -88,7 +84,6 @@ public AnalyzerProvider get(IndexSettings indexSettings, Environment environm protected AnalyzerProvider create(Version version) { assert Version.CURRENT.equals(version) == false; Analyzer analyzer = create.apply(version); - analyzer.setVersion(version.luceneVersion); return new PreBuiltAnalyzerProvider(getName(), AnalyzerScope.INDICES, analyzer); } diff --git a/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java b/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java index 6fff247df63d7..85d25aaa753e6 100644 --- a/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java +++ b/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java @@ -44,7 +44,6 @@ public class SimpleAnalyzerProvider extends AbstractIndexAnalyzerProvider