diff --git a/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index ca9c5576cd4..4955219f5b9 100644 --- a/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -134,7 +134,7 @@ public class TransportBulkAction extends TransportAction badIndexNames = new ArrayList<>(); + for (int i = randomIntBetween(1, 5); i > 0; i--) { + badIndexNames.add("INVALID.NAME" + i); + } boolean expectFailure = false; for (int i = 0; i < bulkEntryCount; i++) { expectFailure |= expectedFailures[i] = randomBoolean(); - builder.add(client().prepareIndex().setIndex(expectedFailures[i] ? "INVALID.NAME" : "test").setType("type1").setId("1").setSource("field", 1)); + String name; + if (expectedFailures[i]) { + name = randomFrom(badIndexNames); + } else { + name = "test"; + } + builder.add(client().prepareIndex().setIndex(name).setType("type1").setId("1").setSource("field", 1)); } BulkResponse bulkResponse = builder.get(); assertThat(bulkResponse.hasFailures(), is(expectFailure));