Skip to content

Commit 178b25f

Browse files
committed
Fix standard filter BWC check to allow for cacheing bug (#62649)
The `standard` tokenfilter was removed by #33310, and should have been unuseable in any indexes created since 7.0. However, a cacheing bug fixed by #51092 meant that it was still possible in certain circumstances to create indexes referencing the standard filter in versions up to 7.5.2. Our checks in AnalysisModule still refer to 7.0.0, however, meaning that a cluster that contains one of these rogue indexes cannot be upgraded. This commit adjusts the AnalysisModule checks so that we only refuse to build a mapping referring to standard filter if the index created version is 7.6 or later. Fixes #62644
1 parent ecf264f commit 178b25f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ static Map<String, PreConfiguredTokenFilter> setupPreConfiguredTokenFilters(List
181181
// Add "standard" for old indices (bwc)
182182
preConfiguredTokenFilters.register( "standard",
183183
PreConfiguredTokenFilter.elasticsearchVersion("standard", true, (reader, version) -> {
184-
if (version.before(Version.V_7_0_0)) {
184+
// This was originally removed in 7_0_0 but due to a cacheing bug it was still possible
185+
// in certain circumstances to create a new index referencing the standard token filter
186+
// until version 7_5_2
187+
if (version.before(Version.V_7_6_0)) {
185188
deprecationLogger.deprecate("standard_deprecation",
186189
"The [standard] token filter is deprecated and will be removed in a future version.");
187190
} else {

server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,28 +228,27 @@ public void testUnderscoreInAnalyzerName() throws IOException {
228228
}
229229

230230
public void testStandardFilterBWC() throws IOException {
231-
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT.minimumCompatibilityVersion());
232-
// bwc deprecation
231+
// standard tokenfilter should have been removed entirely in the 7x line. However, a
232+
// cacheing bug meant that it was still possible to create indexes using a standard
233+
// filter until 7.6
233234
{
235+
Version version = VersionUtils.randomVersionBetween(random(), Version.V_7_6_0, Version.CURRENT);
234236
final Settings settings = Settings.builder().put("index.analysis.analyzer.my_standard.tokenizer", "standard")
235237
.put("index.analysis.analyzer.my_standard.filter", "standard")
236238
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
237239
.put(IndexMetadata.SETTING_VERSION_CREATED, version)
238240
.build();
239-
IndexAnalyzers analyzers = getIndexAnalyzers(settings);
240-
assertTokenStreamContents(analyzers.get("my_standard").tokenStream("", "test"), new String[]{"test"});
241-
assertWarnings("The [standard] token filter is deprecated and will be removed in a future version.");
241+
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> getIndexAnalyzers(settings));
242+
assertThat(exc.getMessage(), equalTo("The [standard] token filter has been removed."));
242243
}
243-
// removal
244244
{
245-
final Settings settings = Settings.builder()
246-
.put("index.analysis.analyzer.my_standard.tokenizer", "standard")
245+
Version version = VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.V_7_5_2);
246+
final Settings settings = Settings.builder().put("index.analysis.analyzer.my_standard.tokenizer", "standard")
247247
.put("index.analysis.analyzer.my_standard.filter", "standard")
248-
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
249-
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_7_0_0)
248+
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetadata.SETTING_VERSION_CREATED, version)
250249
.build();
251-
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> getIndexAnalyzers(settings));
252-
assertThat(exc.getMessage(), equalTo("The [standard] token filter has been removed."));
250+
getIndexAnalyzers(settings);
251+
assertWarnings("The [standard] token filter is deprecated and will be removed in a future version.");
253252
}
254253
}
255254

0 commit comments

Comments
 (0)