From 7a90048ec96a23437a2dbe0aa7cac080af4214ba Mon Sep 17 00:00:00 2001
From: Alan Woodward <romseygeek@apache.org>
Date: Fri, 18 Sep 2020 17:35:15 +0100
Subject: [PATCH 1/2] Fix standard filter BWC check to allow for cacheing bug

---
 .../indices/analysis/AnalysisModule.java      |  2 +-
 .../indices/analysis/AnalysisModuleTests.java | 24 +++++++++++++++----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java b/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java
index 1e01474efc61b..328201f9c0a08 100644
--- a/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java
+++ b/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java
@@ -181,7 +181,7 @@ static Map<String, PreConfiguredTokenFilter> setupPreConfiguredTokenFilters(List
         // Add "standard" for old indices (bwc)
         preConfiguredTokenFilters.register( "standard",
             PreConfiguredTokenFilter.elasticsearchVersion("standard", true, (reader, version) -> {
-                if (version.before(Version.V_7_0_0)) {
+                if (version.before(Version.V_7_6_0)) {
                     deprecationLogger.deprecate("standard_deprecation",
                         "The [standard] token filter is deprecated and will be removed in a future version.");
                 } else {
diff --git a/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java b/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java
index cc4c6f495fbfd..9b7d3e8d33716 100644
--- a/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java
+++ b/server/src/test/java/org/elasticsearch/indices/analysis/AnalysisModuleTests.java
@@ -228,14 +228,28 @@ public void testUnderscoreInAnalyzerName() throws IOException {
         }
     }
 
-    public void testStandardFilterBWC() {
-        Version version = VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.CURRENT);
-        final Settings settings = Settings.builder().put("index.analysis.analyzer.my_standard.tokenizer", "standard")
+    public void testStandardFilterBWC() throws IOException {
+        // standard tokenfilter should have been removed entirely in the 7x line.  However, a
+        // cacheing bug meant that it was still possible to create indexes using a standard
+        // filter until 7.6
+        {
+            Version version = VersionUtils.randomVersionBetween(random(), Version.V_7_6_0, Version.CURRENT);
+            final Settings settings = Settings.builder().put("index.analysis.analyzer.my_standard.tokenizer", "standard")
                 .put("index.analysis.analyzer.my_standard.filter", "standard")
                 .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetadata.SETTING_VERSION_CREATED, version)
                 .build();
-        IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> getIndexAnalyzers(settings));
-        assertThat(exc.getMessage(), equalTo("The [standard] token filter has been removed."));
+            IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> getIndexAnalyzers(settings));
+            assertThat(exc.getMessage(), equalTo("The [standard] token filter has been removed."));
+        }
+        {
+            Version version = VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.V_7_5_2);
+            final Settings settings = Settings.builder().put("index.analysis.analyzer.my_standard.tokenizer", "standard")
+                .put("index.analysis.analyzer.my_standard.filter", "standard")
+                .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetadata.SETTING_VERSION_CREATED, version)
+                .build();
+            getIndexAnalyzers(settings);
+            assertWarnings("The [standard] token filter is deprecated and will be removed in a future version.");
+        }
     }
 
     /**

From 2f41c464f878627da8d982615044d72122201382 Mon Sep 17 00:00:00 2001
From: Alan Woodward <romseygeek@apache.org>
Date: Sun, 20 Sep 2020 17:31:17 +0100
Subject: [PATCH 2/2] add comment

---
 .../org/elasticsearch/indices/analysis/AnalysisModule.java     | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java b/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java
index 328201f9c0a08..c3b5bbf7d0c13 100644
--- a/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java
+++ b/server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java
@@ -181,6 +181,9 @@ static Map<String, PreConfiguredTokenFilter> setupPreConfiguredTokenFilters(List
         // Add "standard" for old indices (bwc)
         preConfiguredTokenFilters.register( "standard",
             PreConfiguredTokenFilter.elasticsearchVersion("standard", true, (reader, version) -> {
+                // This was originally removed in 7_0_0 but due to a cacheing bug it was still possible
+                // in certain circumstances to create a new index referencing the standard token filter
+                // until version 7_5_2
                 if (version.before(Version.V_7_6_0)) {
                     deprecationLogger.deprecate("standard_deprecation",
                         "The [standard] token filter is deprecated and will be removed in a future version.");