Skip to content

Commit d7e279b

Browse files
authored
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 ea2dbd9 commit d7e279b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

+4-1
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

+19-5
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,28 @@ public void testUnderscoreInAnalyzerName() throws IOException {
228228
}
229229
}
230230

231-
public void testStandardFilterBWC() {
232-
Version version = VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.CURRENT);
233-
final Settings settings = Settings.builder().put("index.analysis.analyzer.my_standard.tokenizer", "standard")
231+
public void testStandardFilterBWC() throws IOException {
232+
// standard tokenfilter should have been removed entirely in the 7x line. However, a
233+
// cacheing bug meant that it was still possible to create indexes using a standard
234+
// filter until 7.6
235+
{
236+
Version version = VersionUtils.randomVersionBetween(random(), Version.V_7_6_0, Version.CURRENT);
237+
final Settings settings = Settings.builder().put("index.analysis.analyzer.my_standard.tokenizer", "standard")
234238
.put("index.analysis.analyzer.my_standard.filter", "standard")
235239
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetadata.SETTING_VERSION_CREATED, version)
236240
.build();
237-
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> getIndexAnalyzers(settings));
238-
assertThat(exc.getMessage(), equalTo("The [standard] token filter has been removed."));
241+
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> getIndexAnalyzers(settings));
242+
assertThat(exc.getMessage(), equalTo("The [standard] token filter has been removed."));
243+
}
244+
{
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")
247+
.put("index.analysis.analyzer.my_standard.filter", "standard")
248+
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetadata.SETTING_VERSION_CREATED, version)
249+
.build();
250+
getIndexAnalyzers(settings);
251+
assertWarnings("The [standard] token filter is deprecated and will be removed in a future version.");
252+
}
239253
}
240254

241255
/**

0 commit comments

Comments
 (0)