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 397c1b2c922..40239cbf385 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 5a0cf81cc37..2319b825892 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 class PolishAnalyzerProvider extends 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 f3222753fab..2f91c19c1b7 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 49c18d5c1d7..825f8241d3e 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 38c5beaf9d8..8d780bdd448 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.ru.RussianAnalyzer; 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 @@ import static java.util.Collections.unmodifiableMap; 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); + DEPRECATION_LOGGER.deprecate( + "analyzer.version", + "Setting [version] on analysis [" + name + "] is deprecated, no longer used, and will be removed in a future version." + ); } - // 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); - } - // 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 aa3343f69b1..d2c5384153b 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 class PreBuiltAnalyzerProviderFactory extends PreConfiguredAnalysisCompon 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 6fff247df63..85d25aaa753 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