Skip to content

Commit 5ed66a3

Browse files
committed
Revert removal of 7.x related code from analysis common
This reverts elastic#113009 and re-adds previous v7 tests since we now support v7 indices as read-only on v9.
1 parent 3fce042 commit 5ed66a3

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/CommonAnalysisPluginTests.java

+106
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ public void testNGramFilterInCustomAnalyzerDeprecationError() throws IOException
5353
ex.getMessage()
5454
);
5555
}
56+
57+
final Settings settingsPre7 = Settings.builder()
58+
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
59+
.put(
60+
IndexMetadata.SETTING_VERSION_CREATED,
61+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_6_0)
62+
)
63+
.put("index.analysis.analyzer.custom_analyzer.type", "custom")
64+
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard")
65+
.putList("index.analysis.analyzer.custom_analyzer.filter", "my_ngram")
66+
.put("index.analysis.filter.my_ngram.type", "nGram")
67+
.build();
68+
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) {
69+
createTestAnalysis(IndexSettingsModule.newIndexSettings("index", settingsPre7), settingsPre7, commonAnalysisPlugin);
70+
assertWarnings(
71+
"The [nGram] token filter name is deprecated and will be removed in a future version. "
72+
+ "Please change the filter name to [ngram] instead."
73+
);
74+
}
5675
}
5776

5877
/**
@@ -83,13 +102,66 @@ public void testEdgeNGramFilterInCustomAnalyzerDeprecationError() throws IOExcep
83102
ex.getMessage()
84103
);
85104
}
105+
106+
final Settings settingsPre7 = Settings.builder()
107+
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
108+
.put(
109+
IndexMetadata.SETTING_VERSION_CREATED,
110+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_6_0)
111+
)
112+
.put("index.analysis.analyzer.custom_analyzer.type", "custom")
113+
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard")
114+
.putList("index.analysis.analyzer.custom_analyzer.filter", "my_ngram")
115+
.put("index.analysis.filter.my_ngram.type", "edgeNGram")
116+
.build();
117+
118+
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) {
119+
createTestAnalysis(IndexSettingsModule.newIndexSettings("index", settingsPre7), settingsPre7, commonAnalysisPlugin);
120+
assertWarnings(
121+
"The [edgeNGram] token filter name is deprecated and will be removed in a future version. "
122+
+ "Please change the filter name to [edge_ngram] instead."
123+
);
124+
}
86125
}
87126

88127
/**
89128
* Check that we log a deprecation warning for "nGram" and "edgeNGram" tokenizer names with 7.6 and
90129
* disallow usages for indices created after 8.0
91130
*/
92131
public void testNGramTokenizerDeprecation() throws IOException {
132+
// tests for prebuilt tokenizer
133+
doTestPrebuiltTokenizerDeprecation(
134+
"nGram",
135+
"ngram",
136+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
137+
false
138+
);
139+
doTestPrebuiltTokenizerDeprecation(
140+
"edgeNGram",
141+
"edge_ngram",
142+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
143+
false
144+
);
145+
doTestPrebuiltTokenizerDeprecation(
146+
"nGram",
147+
"ngram",
148+
IndexVersionUtils.randomVersionBetween(
149+
random(),
150+
IndexVersions.V_7_6_0,
151+
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
152+
),
153+
true
154+
);
155+
doTestPrebuiltTokenizerDeprecation(
156+
"edgeNGram",
157+
"edge_ngram",
158+
IndexVersionUtils.randomVersionBetween(
159+
random(),
160+
IndexVersions.V_7_6_0,
161+
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
162+
),
163+
true
164+
);
93165
expectThrows(
94166
IllegalArgumentException.class,
95167
() -> doTestPrebuiltTokenizerDeprecation(
@@ -108,6 +180,40 @@ public void testNGramTokenizerDeprecation() throws IOException {
108180
true
109181
)
110182
);
183+
184+
// same batch of tests for custom tokenizer definition in the settings
185+
doTestCustomTokenizerDeprecation(
186+
"nGram",
187+
"ngram",
188+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
189+
false
190+
);
191+
doTestCustomTokenizerDeprecation(
192+
"edgeNGram",
193+
"edge_ngram",
194+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
195+
false
196+
);
197+
doTestCustomTokenizerDeprecation(
198+
"nGram",
199+
"ngram",
200+
IndexVersionUtils.randomVersionBetween(
201+
random(),
202+
IndexVersions.V_7_6_0,
203+
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
204+
),
205+
true
206+
);
207+
doTestCustomTokenizerDeprecation(
208+
"edgeNGram",
209+
"edge_ngram",
210+
IndexVersionUtils.randomVersionBetween(
211+
random(),
212+
IndexVersions.V_7_6_0,
213+
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
214+
),
215+
true
216+
);
111217
expectThrows(
112218
IllegalArgumentException.class,
113219
() -> doTestCustomTokenizerDeprecation(

0 commit comments

Comments
 (0)