diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java index 2eca1433935..dfb8deac58c 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java @@ -112,7 +112,7 @@ class BulkByScrollParallelizationHelper { (sum, term) -> sum + term )); Set counts = new HashSet<>(countsByIndex.values()); - int leastShards = Collections.min(counts); + int leastShards = counts.isEmpty() ? 1 : Collections.min(counts); return Math.min(leastShards, AUTO_SLICE_CEILING); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java index 5bef735be5e..c6a53fdcfae 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java @@ -306,4 +306,13 @@ public class DeleteByQueryBasicTests extends ReindexTestCase { } + public void testMissingSources() { + BulkByScrollResponse response = updateByQuery() + .source("missing-index-*") + .refresh(true) + .setSlices(AbstractBulkByScrollRequest.AUTO_SLICES) + .get(); + assertThat(response, matcher().deleted(0).slices(hasSize(0))); + } + } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java index 9159f39708f..d95ab555914 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java @@ -157,5 +157,13 @@ public class ReindexBasicTests extends ReindexTestCase { assertHitCount(client().prepareSearch("dest").setSize(0).get(), allDocs.size()); } + public void testMissingSources() { + BulkByScrollResponse response = updateByQuery() + .source("missing-index-*") + .refresh(true) + .setSlices(AbstractBulkByScrollRequest.AUTO_SLICES) + .get(); + assertThat(response, matcher().created(0).slices(hasSize(0))); + } } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java index 91a92005c2c..7351f3eb062 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java @@ -160,4 +160,13 @@ public class UpdateByQueryBasicTests extends ReindexTestCase { assertEquals(2, client().prepareGet(index, "test", Integer.toString(randomDoc)).get().getVersion()); } } + + public void testMissingSources() { + BulkByScrollResponse response = updateByQuery() + .source("missing-index-*") + .refresh(true) + .setSlices(AbstractBulkByScrollRequest.AUTO_SLICES) + .get(); + assertThat(response, matcher().updated(0).slices(hasSize(0))); + } }