@@ -270,6 +270,37 @@ public void testFieldAliasWithMismatchedNestedScope() throws Throwable {
270
270
assertThat (e .getMessage (), containsString ("Invalid [path] value [nested.field] for field alias [alias]" ));
271
271
}
272
272
273
+ public void testTotalFieldsLimitWithFieldAlias () throws Throwable {
274
+ String mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
275
+ .startObject ("properties" )
276
+ .startObject ("alias" )
277
+ .field ("type" , "alias" )
278
+ .field ("path" , "field" )
279
+ .endObject ()
280
+ .startObject ("field" )
281
+ .field ("type" , "text" )
282
+ .endObject ()
283
+ .endObject ()
284
+ .endObject ().endObject ());
285
+
286
+ DocumentMapper documentMapper = createIndex ("test1" ).mapperService ()
287
+ .merge ("type" , new CompressedXContent (mapping ), MergeReason .MAPPING_UPDATE );
288
+
289
+ // Set the total fields limit to the number of non-alias fields, to verify that adding
290
+ // a field alias pushes the mapping over the limit.
291
+ int numFields = documentMapper .mapping ().metadataMappers .length + 2 ;
292
+ int numNonAliasFields = numFields - 1 ;
293
+
294
+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> {
295
+ Settings settings = Settings .builder ()
296
+ .put (MapperService .INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING .getKey (), numNonAliasFields )
297
+ .build ();
298
+ createIndex ("test2" , settings ).mapperService ()
299
+ .merge ("type" , new CompressedXContent (mapping ), MergeReason .MAPPING_UPDATE );
300
+ });
301
+ assertEquals ("Limit of total fields [" + numNonAliasFields + "] in index [test2] has been exceeded" , e .getMessage ());
302
+ }
303
+
273
304
public void testForbidMultipleTypes () throws IOException {
274
305
String mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" ).endObject ().endObject ());
275
306
MapperService mapperService = createIndex ("test" ).mapperService ();
0 commit comments