16
16
import org .elasticsearch .client .ResponseException ;
17
17
import org .elasticsearch .client .RestClient ;
18
18
import org .elasticsearch .client .WarningsHandler ;
19
+ import org .elasticsearch .cluster .metadata .IndexMetadata ;
19
20
import org .elasticsearch .common .Strings ;
20
21
import org .elasticsearch .common .settings .SecureString ;
21
22
import org .elasticsearch .common .settings .Settings ;
24
25
import org .elasticsearch .core .Booleans ;
25
26
import org .elasticsearch .core .PathUtils ;
26
27
import org .elasticsearch .test .rest .ESRestTestCase ;
28
+ import org .elasticsearch .xcontent .ToXContent ;
27
29
import org .elasticsearch .xcontent .XContentBuilder ;
28
30
import org .elasticsearch .xcontent .XContentFactory ;
29
31
import org .elasticsearch .xcontent .XContentType ;
35
37
import java .util .Map ;
36
38
import java .util .stream .Collectors ;
37
39
40
+ import static org .elasticsearch .cluster .metadata .IndexMetadata .SETTING_NUMBER_OF_SHARDS ;
38
41
import static org .hamcrest .Matchers .containsString ;
39
42
import static org .hamcrest .Matchers .hasKey ;
40
43
import static org .hamcrest .Matchers .hasSize ;
@@ -79,9 +82,9 @@ public void setupIndex() throws IOException {
79
82
String snapshotName = "snap" ;
80
83
List <String > indices ;
81
84
if (oldVersion .before (Version .fromString ("6.0.0" ))) {
82
- indices = Arrays .asList ("filebeat" , "winlogbeat" , "custom" , "nested" );
85
+ indices = Arrays .asList ("filebeat" , "winlogbeat" , "custom" , "nested" , "standard_token_filter" );
83
86
} else {
84
- indices = Arrays .asList ("filebeat" , "custom" , "nested" );
87
+ indices = Arrays .asList ("filebeat" , "custom" , "nested" , "standard_token_filter" );
85
88
}
86
89
87
90
int oldEsPort = Integer .parseInt (System .getProperty ("tests.es.port" ));
@@ -91,6 +94,20 @@ public void setupIndex() throws IOException {
91
94
if (oldVersion .before (Version .fromString ("6.0.0" ))) {
92
95
assertOK (oldEs .performRequest (createIndex ("winlogbeat" , "winlogbeat.json" )));
93
96
}
97
+ assertOK (
98
+ oldEs .performRequest (
99
+ createIndex (
100
+ "standard_token_filter" ,
101
+ "standard_token_filter.json" ,
102
+ Settings .builder ()
103
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
104
+ .put ("index.analysis.analyzer.custom_analyzer.type" , "custom" )
105
+ .put ("index.analysis.analyzer.custom_analyzer.tokenizer" , "standard" )
106
+ .put ("index.analysis.analyzer.custom_analyzer.filter" , "standard" )
107
+ .build ()
108
+ )
109
+ )
110
+ );
94
111
assertOK (oldEs .performRequest (createIndex ("custom" , "custom.json" )));
95
112
assertOK (oldEs .performRequest (createIndex ("nested" , "nested.json" )));
96
113
@@ -142,6 +159,12 @@ public void setupIndex() throws IOException {
142
159
doc3 .setJsonEntity (Strings .toString (bodyDoc3 ));
143
160
assertOK (oldEs .performRequest (doc3 ));
144
161
162
+ Request doc4 = new Request ("POST" , "/" + "standard_token_filter" + "/" + "doc" );
163
+ doc4 .addParameter ("refresh" , "true" );
164
+ XContentBuilder bodyDoc4 = XContentFactory .jsonBuilder ().startObject ().field ("content" , "Doc 1" ).endObject ();
165
+ doc4 .setJsonEntity (Strings .toString (bodyDoc4 ));
166
+ assertOK (oldEs .performRequest (doc4 ));
167
+
145
168
// register repo on old ES and take snapshot
146
169
Request createRepoRequest = new Request ("PUT" , "/_snapshot/" + repoName );
147
170
createRepoRequest .setJsonEntity (Strings .format ("""
@@ -170,15 +193,21 @@ public void setupIndex() throws IOException {
170
193
}
171
194
172
195
private Request createIndex (String indexName , String file ) throws IOException {
196
+ return createIndex (indexName , file , Settings .EMPTY );
197
+ }
198
+
199
+ private Request createIndex (String indexName , String file , Settings settings ) throws IOException {
173
200
Request createIndex = new Request ("PUT" , "/" + indexName );
174
201
int numberOfShards = randomIntBetween (1 , 3 );
175
202
176
- XContentBuilder builder = XContentFactory .jsonBuilder ()
177
- .startObject ()
178
- .startObject ("settings" )
179
- .field ("index.number_of_shards" , numberOfShards )
180
- .endObject ()
181
- .startObject ("mappings" );
203
+ XContentBuilder builder = XContentFactory .jsonBuilder ().startObject ();
204
+
205
+ builder .startObject ("settings" );
206
+ builder .field (SETTING_NUMBER_OF_SHARDS , numberOfShards );
207
+ settings .toXContent (builder , ToXContent .EMPTY_PARAMS );
208
+ builder .endObject ();
209
+
210
+ builder .startObject ("mappings" );
182
211
builder .rawValue (OldMappingsIT .class .getResourceAsStream (file ), XContentType .JSON );
183
212
builder .endObject ().endObject ();
184
213
@@ -198,6 +227,21 @@ public void testMappingOk() throws IOException {
198
227
}
199
228
}
200
229
230
+ public void testStandardTokenFilter () throws IOException {
231
+ Request search = new Request ("POST" , "/" + "standard_token_filter" + "/_search" );
232
+ XContentBuilder query = XContentBuilder .builder (XContentType .JSON .xContent ())
233
+ .startObject ()
234
+ .startObject ("query" )
235
+ .startObject ("match_all" )
236
+ .endObject ()
237
+ .endObject ()
238
+ .endObject ();
239
+ search .setJsonEntity (Strings .toString (query ));
240
+ Map <String , Object > response = entityAsMap (client ().performRequest (search ));
241
+ List <?> hits = (List <?>) (XContentMapValues .extractValue ("hits.hits" , response ));
242
+ assertThat (hits , hasSize (1 ));
243
+ }
244
+
201
245
public void testSearchKeyword () throws IOException {
202
246
Request search = new Request ("POST" , "/" + "custom" + "/_search" );
203
247
XContentBuilder query = XContentBuilder .builder (XContentType .JSON .xContent ())
0 commit comments