diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuilders.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuilders.java index 007ff757911..8d04941cf36 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuilders.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuilders.java @@ -135,6 +135,11 @@ final class RemoteRequestBuilders { request.addParameter(storedFieldsParamName, fields.toString()); } + if (remoteVersion.onOrAfter(Version.fromId(6030099))) { + // allow_partial_results introduced in 6.3, running remote reindex against earlier versions still silently discards RED shards. + request.addParameter("allow_partial_search_results", "false"); + } + // EMPTY is safe here because we're not calling namedObject try (XContentBuilder entity = JsonXContent.contentBuilder(); XContentParser queryParser = XContentHelper diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ClientScrollableHitSourceTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ClientScrollableHitSourceTests.java index 37425a7c600..6526f608109 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ClientScrollableHitSourceTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ClientScrollableHitSourceTests.java @@ -117,7 +117,7 @@ public class ClientScrollableHitSourceTests extends ESTestCase { client.awaitOperation(); ++expectedSearchRetries; } - + client.validateRequest(SearchAction.INSTANCE, (SearchRequest r) -> assertTrue(r.allowPartialSearchResults() == Boolean.FALSE)); SearchResponse searchResponse = createSearchResponse(); client.respond(SearchAction.INSTANCE, searchResponse); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuildersTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuildersTests.java index 399b6fa28f4..4337ce9abce 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuildersTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuildersTests.java @@ -41,6 +41,7 @@ import static org.elasticsearch.index.reindex.remote.RemoteRequestBuilders.DEPRE import static org.elasticsearch.index.reindex.remote.RemoteRequestBuilders.clearScroll; import static org.elasticsearch.index.reindex.remote.RemoteRequestBuilders.initialSearch; import static org.elasticsearch.index.reindex.remote.RemoteRequestBuilders.scroll; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.either; import static org.hamcrest.Matchers.empty; @@ -206,6 +207,22 @@ public class RemoteRequestBuildersTests extends ESTestCase { } } + public void testInitialSearchDisallowPartialResults() { + final String allowPartialParamName = "allow_partial_search_results"; + final int v6_3 = 6030099; + + BytesReference query = new BytesArray("{}"); + SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder()); + + Version disallowVersion = Version.fromId(between(v6_3, Version.CURRENT.id)); + Map params = initialSearch(searchRequest, query, disallowVersion).getParameters(); + assertEquals("false", params.get(allowPartialParamName)); + + Version allowVersion = Version.fromId(between(0, v6_3-1)); + params = initialSearch(searchRequest, query, allowVersion).getParameters(); + assertThat(params.keySet(), not(contains(allowPartialParamName))); + } + private void assertScroll(Version remoteVersion, Map params, TimeValue requested) { // V_5_0_0 if (remoteVersion.before(Version.fromId(5000099))) { diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/35_search_failures.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/35_search_failures.yml index 5fd888f77a1..44b36119fbc 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/35_search_failures.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/35_search_failures.yml @@ -28,15 +28,15 @@ source: throw new IllegalArgumentException("Cats!") dest: index: dest - - match: {created: 0} - - match: {updated: 0} - - match: {version_conflicts: 0} - - match: {batches: 0} - - match: {failures.0.shard: 0} - - match: {failures.0.index: source} - - is_true: failures.0.node - - match: {failures.0.reason.type: script_exception} - - match: {failures.0.reason.reason: runtime error} - - match: {failures.0.reason.caused_by.type: illegal_argument_exception} - - match: {failures.0.reason.caused_by.reason: Cats!} - - gte: { took: 0 } + - match: {error.type: search_phase_execution_exception} + - match: {error.reason: "Partial shards failure"} + - match: {error.phase: query} + - match: {error.root_cause.0.type: script_exception} + - match: {error.root_cause.0.reason: runtime error} + - match: {error.failed_shards.0.shard: 0} + - match: {error.failed_shards.0.index: source} + - is_true: error.failed_shards.0.node + - match: {error.failed_shards.0.reason.type: script_exception} + - match: {error.failed_shards.0.reason.reason: runtime error} + - match: {error.failed_shards.0.reason.caused_by.type: illegal_argument_exception} + - match: {error.failed_shards.0.reason.caused_by.reason: Cats!} diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/35_search_failure.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/35_search_failure.yml index da94187f50a..5a22eec88c0 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/35_search_failure.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/35_search_failure.yml @@ -25,14 +25,15 @@ script: lang: painless source: throw new IllegalArgumentException("Cats!") - - match: {updated: 0} - - match: {version_conflicts: 0} - - match: {batches: 0} - - match: {failures.0.shard: 0} - - match: {failures.0.index: source} - - is_true: failures.0.node - - match: {failures.0.reason.type: script_exception} - - match: {failures.0.reason.reason: runtime error} - - match: {failures.0.reason.caused_by.type: illegal_argument_exception} - - match: {failures.0.reason.caused_by.reason: Cats!} - - gte: { took: 0 } + - match: {error.type: search_phase_execution_exception} + - match: {error.reason: "Partial shards failure"} + - match: {error.phase: query} + - match: {error.root_cause.0.type: script_exception} + - match: {error.root_cause.0.reason: runtime error} + - match: {error.failed_shards.0.shard: 0} + - match: {error.failed_shards.0.index: source} + - is_true: error.failed_shards.0.node + - match: {error.failed_shards.0.reason.type: script_exception} + - match: {error.failed_shards.0.reason.reason: runtime error} + - match: {error.failed_shards.0.reason.caused_by.type: illegal_argument_exception} + - match: {error.failed_shards.0.reason.caused_by.reason: Cats!} diff --git a/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java b/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java index a3fbf8f20d4..41bad478898 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/ClientScrollableHitSource.java @@ -64,6 +64,7 @@ public class ClientScrollableHitSource extends ScrollableHitSource { super(logger, backoffPolicy, threadPool, countSearchRetry, onResponse, fail); this.client = client; this.firstSearchRequest = firstSearchRequest; + firstSearchRequest.allowPartialSearchResults(false); } @Override