@@ -53,6 +53,25 @@ public void testNGramFilterInCustomAnalyzerDeprecationError() throws IOException
53
53
ex .getMessage ()
54
54
);
55
55
}
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
+ }
56
75
}
57
76
58
77
/**
@@ -83,13 +102,66 @@ public void testEdgeNGramFilterInCustomAnalyzerDeprecationError() throws IOExcep
83
102
ex .getMessage ()
84
103
);
85
104
}
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
+ }
86
125
}
87
126
88
127
/**
89
128
* Check that we log a deprecation warning for "nGram" and "edgeNGram" tokenizer names with 7.6 and
90
129
* disallow usages for indices created after 8.0
91
130
*/
92
131
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
+ );
93
165
expectThrows (
94
166
IllegalArgumentException .class ,
95
167
() -> doTestPrebuiltTokenizerDeprecation (
@@ -108,6 +180,40 @@ public void testNGramTokenizerDeprecation() throws IOException {
108
180
true
109
181
)
110
182
);
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
+ );
111
217
expectThrows (
112
218
IllegalArgumentException .class ,
113
219
() -> doTestCustomTokenizerDeprecation (
0 commit comments