@@ -365,6 +365,37 @@ public void testFieldAliasWithMismatchedNestedScope() throws Throwable {
365
365
assertThat (e .getMessage (), containsString ("Invalid [path] value [nested.field] for field alias [alias]" ));
366
366
}
367
367
368
+ public void testTotalFieldsLimitWithFieldAlias () throws Throwable {
369
+ String mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
370
+ .startObject ("properties" )
371
+ .startObject ("alias" )
372
+ .field ("type" , "alias" )
373
+ .field ("path" , "field" )
374
+ .endObject ()
375
+ .startObject ("field" )
376
+ .field ("type" , "text" )
377
+ .endObject ()
378
+ .endObject ()
379
+ .endObject ().endObject ());
380
+
381
+ DocumentMapper documentMapper = createIndex ("test1" ).mapperService ()
382
+ .merge ("type" , new CompressedXContent (mapping ), MergeReason .MAPPING_UPDATE , true );
383
+
384
+ // Set the total fields limit to the number of non-alias fields, to verify that adding
385
+ // a field alias pushes the mapping over the limit.
386
+ int numFields = documentMapper .mapping ().metadataMappers .length + 2 ;
387
+ int numNonAliasFields = numFields - 1 ;
388
+
389
+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> {
390
+ Settings settings = Settings .builder ()
391
+ .put (MapperService .INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING .getKey (), numNonAliasFields )
392
+ .build ();
393
+ createIndex ("test2" , settings ).mapperService ()
394
+ .merge ("type" , new CompressedXContent (mapping ), MergeReason .MAPPING_UPDATE , true );
395
+ });
396
+ assertEquals ("Limit of total fields [" + numNonAliasFields + "] in index [test2] has been exceeded" , e .getMessage ());
397
+ }
398
+
368
399
public void testForbidMultipleTypes () throws IOException {
369
400
String mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" ).endObject ().endObject ());
370
401
MapperService mapperService = createIndex ("test" ).mapperService ();
0 commit comments