diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 4896bf715a98e..882151553a1b6 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -132,7 +132,7 @@ private static void addRandomField(List existingFieldNames, final int fi mappingBuilder.startObject("properties"); { int subfields = randomIntBetween(1, 10); - while (existingFieldNames.size() < subfields) { + while (existingFieldNames.size() < subfields && fieldCount.get() <= fieldLimit) { addRandomField(existingFieldNames, fieldLimit, mappingBuilder, fieldCount); } }