57
57
58
58
import static org .hamcrest .CoreMatchers .containsString ;
59
59
import static org .hamcrest .Matchers .instanceOf ;
60
+ import static org .hamcrest .Matchers .notNullValue ;
61
+ import static org .hamcrest .Matchers .nullValue ;
60
62
61
63
public class MapperServiceTests extends ESSingleNodeTestCase {
62
64
@@ -127,6 +129,15 @@ public void testIndexIntoDefaultMapping() throws Throwable {
127
129
assertNull (indexService .mapperService ().documentMapper (MapperService .DEFAULT_MAPPING ));
128
130
}
129
131
132
+ public void testPreflightUpdateDoesNotChangeMapping () throws Throwable {
133
+ final MapperService mapperService = createIndex ("test1" ).mapperService ();
134
+ final CompressedXContent mapping = createMappingSpecifyingNumberOfFields (1 );
135
+ mapperService .merge ("type" , mapping , MergeReason .MAPPING_UPDATE_PREFLIGHT );
136
+ assertThat ("field was not created by preflight check" , mapperService .fullName ("field0" ), nullValue ());
137
+ mapperService .merge ("type" , mapping , MergeReason .MAPPING_UPDATE );
138
+ assertThat ("field was not created by mapping update" , mapperService .fullName ("field0" ), notNullValue ());
139
+ }
140
+
130
141
/**
131
142
* Test that we can have at least the number of fields in new mappings that are defined by "index.mapping.total_fields.limit".
132
143
* Any additional field should trigger an IllegalArgumentException.
@@ -141,7 +152,7 @@ public void testTotalFieldsLimit() throws Throwable {
141
152
// adding one more field should trigger exception
142
153
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> {
143
154
createIndex ("test2" , settings ).mapperService ().merge ("type" ,
144
- createMappingSpecifyingNumberOfFields (totalFieldsLimit + 1 ), MergeReason . MAPPING_UPDATE );
155
+ createMappingSpecifyingNumberOfFields (totalFieldsLimit + 1 ), updateOrPreflight () );
145
156
});
146
157
assertTrue (e .getMessage (),
147
158
e .getMessage ().contains ("Limit of total fields [" + totalFieldsLimit + "] in index [test2] has been exceeded" ));
@@ -177,7 +188,7 @@ public void testMappingDepthExceedsLimit() throws Throwable {
177
188
indexService2 .mapperService ().merge ("type" , objectMapping , MergeReason .MAPPING_UPDATE );
178
189
179
190
IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
180
- () -> indexService1 .mapperService ().merge ("type" , objectMapping , MergeReason . MAPPING_UPDATE ));
191
+ () -> indexService1 .mapperService ().merge ("type" , objectMapping , updateOrPreflight () ));
181
192
assertThat (e .getMessage (), containsString ("Limit of mapping depth [1] in index [test1] has been exceeded" ));
182
193
}
183
194
@@ -228,7 +239,7 @@ public void testIndexSortWithNestedFields() throws IOException {
228
239
.endObject ().endObject ()));
229
240
invalidNestedException = expectThrows (IllegalArgumentException .class ,
230
241
() -> indexService .mapperService ().merge ("t" , nestedFieldMapping ,
231
- MergeReason . MAPPING_UPDATE ));
242
+ updateOrPreflight () ));
232
243
assertThat (invalidNestedException .getMessage (),
233
244
containsString ("cannot have nested fields when index sort is activated" ));
234
245
}
@@ -264,7 +275,7 @@ public void testFieldAliasWithMismatchedNestedScope() throws Throwable {
264
275
.endObject ()));
265
276
266
277
IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
267
- () -> mapperService .merge ("type" , mappingUpdate , MergeReason . MAPPING_UPDATE ));
278
+ () -> mapperService .merge ("type" , mappingUpdate , updateOrPreflight () ));
268
279
assertThat (e .getMessage (), containsString ("Invalid [path] value [nested.field] for field alias [alias]" ));
269
280
}
270
281
@@ -292,7 +303,7 @@ public void testTotalFieldsLimitWithFieldAlias() throws Throwable {
292
303
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> {
293
304
createIndex ("test2" ,
294
305
Settings .builder ().put (MapperService .INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING .getKey (), numberOfNonAliasFields ).build ())
295
- .mapperService ().merge ("type" , new CompressedXContent (mapping ), MergeReason . MAPPING_UPDATE );
306
+ .mapperService ().merge ("type" , new CompressedXContent (mapping ), updateOrPreflight () );
296
307
});
297
308
assertEquals ("Limit of total fields [" + numberOfNonAliasFields + "] in index [test2] has been exceeded" , e .getMessage ());
298
309
}
@@ -334,7 +345,7 @@ public void testFieldNameLengthLimit() throws Throwable {
334
345
.endObject ()));
335
346
336
347
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> {
337
- mapperService .merge ("type" , mappingUpdate , MergeReason . MAPPING_UPDATE );
348
+ mapperService .merge ("type" , mappingUpdate , updateOrPreflight () );
338
349
});
339
350
340
351
assertEquals ("Field name [" + testString + "] in index [test1] is too long. " +
@@ -359,7 +370,7 @@ public void testObjectNameLengthLimit() throws Throwable {
359
370
.endObject ().endObject ()));
360
371
361
372
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> {
362
- mapperService .merge ("type" , mapping , MergeReason . MAPPING_UPDATE );
373
+ mapperService .merge ("type" , mapping , updateOrPreflight () );
363
374
});
364
375
365
376
assertEquals ("Field name [" + testString + "] in index [test1] is too long. " +
@@ -388,7 +399,7 @@ public void testAliasFieldNameLengthLimit() throws Throwable {
388
399
.endObject ().endObject ()));
389
400
390
401
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> {
391
- mapperService .merge ("type" , mapping , MergeReason . MAPPING_UPDATE );
402
+ mapperService .merge ("type" , mapping , updateOrPreflight () );
392
403
});
393
404
394
405
assertEquals ("Field name [" + testString + "] in index [test1] is too long. " +
@@ -479,6 +490,10 @@ private boolean assertSameContainedFilters(TokenFilterFactory[] originalTokenFil
479
490
return true ;
480
491
}
481
492
493
+ private static MergeReason updateOrPreflight () {
494
+ return randomFrom (MergeReason .MAPPING_UPDATE , MergeReason .MAPPING_UPDATE_PREFLIGHT );
495
+ }
496
+
482
497
public static final class ReloadableFilterPlugin extends Plugin implements AnalysisPlugin {
483
498
484
499
@ Override
0 commit comments