From 7890b525b603f5fa3cac21b2699ab7428ab7d548 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 6 May 2019 12:10:31 +0200 Subject: [PATCH 1/6] Reindex max_docs parameter name Previously, size could be specified both at outer level and inside the source element. The outer level size has now been renamed to max_docs to avoid confusion, with backwards compatibility and deprecation warnings for using size. Same goes for update/delete-by-query except that we no longer support specifying max_docs inside the body, only as URL query param. Relates #24344 --- .../client/RequestConverters.java | 8 +- .../client/RequestConvertersTests.java | 22 ++++- .../documentation/CRUDDocumentationIT.java | 18 ++-- docs/java-api/docs/update-by-query.asciidoc | 2 +- .../document/delete-by-query.asciidoc | 4 +- .../high-level/document/reindex.asciidoc | 6 +- .../document/update-by-query.asciidoc | 4 +- docs/reference/docs/delete-by-query.asciidoc | 10 +- docs/reference/docs/reindex.asciidoc | 20 ++-- docs/reference/docs/update-by-query.asciidoc | 10 +- .../AbstractAsyncBulkByScrollAction.java | 14 +-- .../AbstractBaseReindexRestHandler.java | 11 ++- .../AbstractBulkByQueryRestHandler.java | 12 ++- .../index/reindex/RestReindexAction.java | 2 +- .../documentation/ReindexDocumentationIT.java | 4 +- .../index/reindex/ReindexBasicTests.java | 6 +- .../reindex/RestDeleteByQueryActionTests.java | 4 +- .../reindex/RestUpdateByQueryActionTests.java | 4 +- .../index/reindex/RoundTripTests.java | 6 +- .../test/delete_by_query/10_basic.yml | 93 +++++++++++++++++++ .../test/delete_by_query/20_validation.yml | 43 ++++++++- .../test/reindex/20_validation.yml | 45 ++++++++- .../rest-api-spec/test/reindex/30_search.yml | 93 +++++++++++++++++++ .../rest-api-spec/test/reindex/90_remote.yml | 70 ++++++++++++++ .../test/update_by_query/10_basic.yml | 67 +++++++++++++ .../test/update_by_query/20_validation.yml | 40 +++++++- .../rest-api-spec/api/delete_by_query.json | 6 +- .../rest-api-spec/api/update_by_query.json | 6 +- .../reindex/AbstractBulkByScrollRequest.java | 54 ++++++++--- .../AbstractBulkByScrollRequestBuilder.java | 16 +++- .../index/reindex/ReindexRequest.java | 4 +- .../AbstractBulkByScrollRequestTestCase.java | 12 ++- .../action/TransportDeleteForecastAction.java | 2 +- 33 files changed, 625 insertions(+), 93 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 023bd1fe63786..64e640b181a5d 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -571,8 +571,8 @@ static Request updateByQuery(UpdateByQueryRequest updateByQueryRequest) throws I if (updateByQueryRequest.getScrollTime() != AbstractBulkByScrollRequest.DEFAULT_SCROLL_TIMEOUT) { params.putParam("scroll", updateByQueryRequest.getScrollTime()); } - if (updateByQueryRequest.getSize() > 0) { - params.putParam("size", Integer.toString(updateByQueryRequest.getSize())); + if (updateByQueryRequest.getMaxDocs() > 0) { + params.putParam("max_docs", Integer.toString(updateByQueryRequest.getMaxDocs())); } request.setEntity(createEntity(updateByQueryRequest, REQUEST_BODY_CONTENT_TYPE)); return request; @@ -598,8 +598,8 @@ static Request deleteByQuery(DeleteByQueryRequest deleteByQueryRequest) throws I if (deleteByQueryRequest.getScrollTime() != AbstractBulkByScrollRequest.DEFAULT_SCROLL_TIMEOUT) { params.putParam("scroll", deleteByQueryRequest.getScrollTime()); } - if (deleteByQueryRequest.getSize() > 0) { - params.putParam("size", Integer.toString(deleteByQueryRequest.getSize())); + if (deleteByQueryRequest.getMaxDocs() > 0) { + params.putParam("max_docs", Integer.toString(deleteByQueryRequest.getMaxDocs())); } request.setEntity(createEntity(deleteByQueryRequest, REQUEST_BODY_CONTENT_TYPE)); return request; diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index 9c5137d54427a..e3884d7174aac 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -430,7 +430,11 @@ public void testReindex() throws IOException { reindexRequest.setDestRouting("=cat"); } if (randomBoolean()) { - reindexRequest.setSize(randomIntBetween(100, 1000)); + if (randomBoolean()) { + reindexRequest.setMaxDocs(randomIntBetween(100, 1000)); + } else { + reindexRequest.setSize(randomIntBetween(100, 1000)); + } } if (randomBoolean()) { reindexRequest.setAbortOnVersionConflict(false); @@ -482,8 +486,12 @@ public void testUpdateByQuery() throws IOException { } if (randomBoolean()) { int size = randomIntBetween(100, 1000); - updateByQueryRequest.setSize(size); - expectedParams.put("size", Integer.toString(size)); + if (randomBoolean()) { + updateByQueryRequest.setMaxDocs(size); + } else { + updateByQueryRequest.setSize(size); + } + expectedParams.put("max_docs", Integer.toString(size)); } if (randomBoolean()) { updateByQueryRequest.setAbortOnVersionConflict(false); @@ -532,8 +540,12 @@ public void testDeleteByQuery() throws IOException { } if (randomBoolean()) { int size = randomIntBetween(100, 1000); - deleteByQueryRequest.setSize(size); - expectedParams.put("size", Integer.toString(size)); + if (randomBoolean()) { + deleteByQueryRequest.setMaxDocs(size); + } else { + deleteByQueryRequest.setSize(size); + } + expectedParams.put("max_docs", Integer.toString(size)); } if (randomBoolean()) { deleteByQueryRequest.setAbortOnVersionConflict(false); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java index fe003d691a830..5b990e8b30cd8 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java @@ -824,9 +824,9 @@ public void testReindex() throws Exception { // tag::reindex-request-conflicts request.setConflicts("proceed"); // <1> // end::reindex-request-conflicts - // tag::reindex-request-size - request.setSize(10); // <1> - // end::reindex-request-size + // tag::reindex-request-maxDocs + request.setMaxDocs(10); // <1> + // end::reindex-request-maxDocs // tag::reindex-request-sourceSize request.setSourceBatchSize(100); // <1> // end::reindex-request-sourceSize @@ -1026,9 +1026,9 @@ public void testUpdateByQuery() throws Exception { // tag::update-by-query-request-query request.setQuery(new TermQueryBuilder("user", "kimchy")); // <1> // end::update-by-query-request-query - // tag::update-by-query-request-size - request.setSize(10); // <1> - // end::update-by-query-request-size + // tag::update-by-query-request-maxDocs + request.setMaxDocs(10); // <1> + // end::update-by-query-request-maxDocs // tag::update-by-query-request-scrollSize request.setBatchSize(100); // <1> // end::update-by-query-request-scrollSize @@ -1148,9 +1148,9 @@ public void testDeleteByQuery() throws Exception { // tag::delete-by-query-request-query request.setQuery(new TermQueryBuilder("user", "kimchy")); // <1> // end::delete-by-query-request-query - // tag::delete-by-query-request-size - request.setSize(10); // <1> - // end::delete-by-query-request-size + // tag::delete-by-query-request-maxDocs + request.setMaxDocs(10); // <1> + // end::delete-by-query-request-maxDocs // tag::delete-by-query-request-scrollSize request.setBatchSize(100); // <1> // end::delete-by-query-request-scrollSize diff --git a/docs/java-api/docs/update-by-query.asciidoc b/docs/java-api/docs/update-by-query.asciidoc index ef58d3754276e..e6726f4bed15f 100644 --- a/docs/java-api/docs/update-by-query.asciidoc +++ b/docs/java-api/docs/update-by-query.asciidoc @@ -51,7 +51,7 @@ otherwise modify the request for matching documents. include-tagged::{client-reindex-tests}/ReindexDocumentationIT.java[update-by-query-size] -------------------------------------------------- -You can also combine `size` with sorting to limit the documents updated: +You can also combine `maxDocs` with sorting to limit the documents updated: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- diff --git a/docs/java-rest/high-level/document/delete-by-query.asciidoc b/docs/java-rest/high-level/document/delete-by-query.asciidoc index 37be8e2f3f4c8..a768dff4c5010 100644 --- a/docs/java-rest/high-level/document/delete-by-query.asciidoc +++ b/docs/java-rest/high-level/document/delete-by-query.asciidoc @@ -39,11 +39,11 @@ include-tagged::{doc-tests-file}[{api}-request-query] -------------------------------------------------- <1> Only copy documents which have field `user` set to `kimchy` -It’s also possible to limit the number of processed documents by setting size. +It’s also possible to limit the number of processed documents by setting maxDocs. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-size] +include-tagged::{doc-tests-file}[{api}-request-maxDocs] -------------------------------------------------- <1> Only copy 10 documents diff --git a/docs/java-rest/high-level/document/reindex.asciidoc b/docs/java-rest/high-level/document/reindex.asciidoc index d78851f3d6a86..ccfb0c9db1a56 100644 --- a/docs/java-rest/high-level/document/reindex.asciidoc +++ b/docs/java-rest/high-level/document/reindex.asciidoc @@ -65,11 +65,11 @@ include-tagged::{doc-tests-file}[{api}-request-query] -------------------------------------------------- <1> Only copy documents which have field `user` set to `kimchy` -It’s also possible to limit the number of processed documents by setting size. +It’s also possible to limit the number of processed documents by setting `maxDocs`. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-size] +include-tagged::{doc-tests-file}[{api}-request-maxDocs] -------------------------------------------------- <1> Only copy 10 documents @@ -90,7 +90,7 @@ include-tagged::{doc-tests-file}[{api}-request-pipeline] <1> set pipeline to `my_pipeline` If you want a particular set of documents from the source index you’ll need to use sort. If possible, prefer a more -selective query to size and sort. +selective query to maxDocs and sort. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- diff --git a/docs/java-rest/high-level/document/update-by-query.asciidoc b/docs/java-rest/high-level/document/update-by-query.asciidoc index be1692c4e9f6a..80c5063c4b109 100644 --- a/docs/java-rest/high-level/document/update-by-query.asciidoc +++ b/docs/java-rest/high-level/document/update-by-query.asciidoc @@ -40,11 +40,11 @@ include-tagged::{doc-tests-file}[{api}-request-query] -------------------------------------------------- <1> Only copy documents which have field `user` set to `kimchy` -It’s also possible to limit the number of processed documents by setting size. +It’s also possible to limit the number of processed documents by setting maxDocs. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-size] +include-tagged::{doc-tests-file}[{api}-request-maxDocs] -------------------------------------------------- <1> Only copy 10 documents diff --git a/docs/reference/docs/delete-by-query.asciidoc b/docs/reference/docs/delete-by-query.asciidoc index f8cb84ab790fa..4dbdd18ca02d3 100644 --- a/docs/reference/docs/delete-by-query.asciidoc +++ b/docs/reference/docs/delete-by-query.asciidoc @@ -571,11 +571,11 @@ sub-request proportionally. * Due to the nature of `slices` each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution. -* Parameters like `requests_per_second` and `size` on a request with `slices` -are distributed proportionally to each sub-request. Combine that with the point -above about distribution being uneven and you should conclude that the using -`size` with `slices` might not result in exactly `size` documents being -deleted. +* Parameters like `requests_per_second` and `max_docs` on a request with +slices` are distributed proportionally to each sub-request. Combine that with +the point above about distribution being uneven and you should conclude that +using `max_docs` with `slices` might not result in exactly `max_docs` documents +being deleted. * Each sub-request gets a slightly different snapshot of the source index though these are all taken at approximately the same time. diff --git a/docs/reference/docs/reindex.asciidoc b/docs/reference/docs/reindex.asciidoc index b085e081b4dd7..2342dab9a40a2 100644 --- a/docs/reference/docs/reindex.asciidoc +++ b/docs/reference/docs/reindex.asciidoc @@ -190,14 +190,14 @@ not a good idea to rely on this behavior. Instead, make sure that IDs are unique using a script. It's also possible to limit the number of processed documents by setting -`size`. This will only copy a single document from `twitter` to +`max_docs`. This will only copy a single document from `twitter` to `new_twitter`: [source,js] -------------------------------------------------- POST _reindex { - "size": 1, + "max_docs": 1, "source": { "index": "twitter" }, @@ -211,14 +211,14 @@ POST _reindex If you want a particular set of documents from the `twitter` index you'll need to use `sort`. Sorting makes the scroll less efficient but in some contexts -it's worth it. If possible, prefer a more selective query to `size` and `sort`. +it's worth it. If possible, prefer a more selective query to `max_docs` and `sort`. This will copy 10000 documents from `twitter` into `new_twitter`: [source,js] -------------------------------------------------- POST _reindex { - "size": 10000, + "max_docs": 10000, "source": { "index": "twitter", "sort": { "date": "desc" } @@ -1111,11 +1111,11 @@ sub-request proportionally. * Due to the nature of `slices` each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution. -* Parameters like `requests_per_second` and `size` on a request with `slices` -are distributed proportionally to each sub-request. Combine that with the point -above about distribution being uneven and you should conclude that the using -`size` with `slices` might not result in exactly `size` documents being -reindexed. +* Parameters like `requests_per_second` and `max_docs` on a request with +`slices` are distributed proportionally to each sub-request. Combine that with +the point above about distribution being uneven and you should conclude that +using `max_docs` with `slices` might not result in exactly `max_docs` documents +being reindexed. * Each sub-request gets a slightly different snapshot of the source index, though these are all taken at approximately the same time. @@ -1232,7 +1232,7 @@ to load only the existing data into the new index and rename any fields if neede ---------------------------------------------------------------- POST _reindex { - "size": 10, + "max_docs": 10, "source": { "index": "twitter", "query": { diff --git a/docs/reference/docs/update-by-query.asciidoc b/docs/reference/docs/update-by-query.asciidoc index 883f6ad2a29e3..163ce17194268 100644 --- a/docs/reference/docs/update-by-query.asciidoc +++ b/docs/reference/docs/update-by-query.asciidoc @@ -602,11 +602,11 @@ sub-request proportionally. * Due to the nature of `slices` each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution. -* Parameters like `requests_per_second` and `size` on a request with `slices` -are distributed proportionally to each sub-request. Combine that with the point -above about distribution being uneven and you should conclude that the using -`size` with `slices` might not result in exactly `size` documents being -updated. +* Parameters like `requests_per_second` and `max_docs` on a request with +`slices` are distributed proportionally to each sub-request. Combine that with +the point above about distribution being uneven and you should conclude that +using `max_docs` with `slices` might not result in exactly `max_docs` documents +being updated. * Each sub-request gets a slightly different snapshot of the source index though these are all taken at approximately the same time. diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractAsyncBulkByScrollAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractAsyncBulkByScrollAction.java index a4b28e6c598d3..c6bfcf13eb113 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractAsyncBulkByScrollAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractAsyncBulkByScrollAction.java @@ -75,7 +75,7 @@ import static java.util.Collections.unmodifiableList; import static org.elasticsearch.action.bulk.BackoffPolicy.exponentialBackoff; import static org.elasticsearch.common.unit.TimeValue.timeValueNanos; -import static org.elasticsearch.index.reindex.AbstractBulkByScrollRequest.SIZE_ALL_MATCHES; +import static org.elasticsearch.index.reindex.AbstractBulkByScrollRequest.MAX_DOCS_ALL_MATCHES; import static org.elasticsearch.rest.RestStatus.CONFLICT; import static org.elasticsearch.search.sort.SortBuilders.fieldSort; @@ -263,8 +263,8 @@ void onScrollResponse(TimeValue lastBatchStartTime, int lastBatchSize, Scrollabl return; } long total = response.getTotalHits(); - if (mainRequest.getSize() > 0) { - total = min(total, mainRequest.getSize()); + if (mainRequest.getMaxDocs() > 0) { + total = min(total, mainRequest.getMaxDocs()); } worker.setTotal(total); AbstractRunnable prepareBulkRequestRunnable = new AbstractRunnable() { @@ -304,9 +304,9 @@ void prepareBulkRequest(TimeValue thisBatchStartTime, ScrollableHitSource.Respon } worker.countBatch(); List hits = response.getHits(); - if (mainRequest.getSize() != SIZE_ALL_MATCHES) { - // Truncate the hits if we have more than the request size - long remaining = max(0, mainRequest.getSize() - worker.getSuccessfullyProcessed()); + if (mainRequest.getMaxDocs() != MAX_DOCS_ALL_MATCHES) { + // Truncate the hits if we have more than the request max docs + long remaining = max(0, mainRequest.getMaxDocs() - worker.getSuccessfullyProcessed()); if (remaining < hits.size()) { hits = hits.subList(0, (int) remaining); } @@ -395,7 +395,7 @@ void onBulkResponse(TimeValue thisBatchStartTime, BulkResponse response) { return; } - if (mainRequest.getSize() != SIZE_ALL_MATCHES && worker.getSuccessfullyProcessed() >= mainRequest.getSize()) { + if (mainRequest.getMaxDocs() != MAX_DOCS_ALL_MATCHES && worker.getSuccessfullyProcessed() >= mainRequest.getMaxDocs()) { // We've processed all the requested docs. refreshAndFinish(emptyList(), emptyList(), false); return; diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java index bf333352dd55c..ebc07811a80d8 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.reindex; -import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; @@ -170,4 +170,13 @@ public static Float parseRequestsPerSecond(RestRequest request) { } return requestsPerSecond; } + + static void setMaxDocsValidateIdentical(AbstractBulkByScrollRequest request, int maxDocs) { + if (request.getMaxDocs() != AbstractBulkByScrollRequest.MAX_DOCS_ALL_MATCHES && request.getMaxDocs() != maxDocs) { + throw new IllegalArgumentException("[max_docs] set to two different values [" + request.getMaxDocs() + "]" + + " and [" + maxDocs + "]"); + } else { + request.setMaxDocs(maxDocs); + } + } } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java index fab94494fe13d..ab8898d15cc04 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -52,11 +53,15 @@ protected void parseInternalRequest(Request internal, RestRequest restRequest, SearchRequest searchRequest = internal.getSearchRequest(); try (XContentParser parser = extractRequestSpecificFields(restRequest, bodyConsumers)) { - RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, internal::setSize); + RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, size -> setMaxDocsFromSearchSize(internal, size)); } searchRequest.source().size(restRequest.paramAsInt("scroll_size", searchRequest.source().size())); + if (restRequest.hasParam("max_docs")) { + setMaxDocsValidateIdentical(internal, restRequest.paramAsInt("max_docs", -1)); + } + String conflicts = restRequest.param("conflicts"); if (conflicts != null) { internal.setConflicts(conflicts); @@ -94,4 +99,9 @@ private XContentParser extractRequestSpecificFields(RestRequest restRequest, parser.getDeprecationHandler(), BytesReference.bytes(builder.map(body)).streamInput()); } } + + private void setMaxDocsFromSearchSize(Request request, int size) { + LoggingDeprecationHandler.INSTANCE.usedDeprecatedName("size", "max_docs"); + setMaxDocsValidateIdentical(request, size); + } } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java index ae9ca0be7ca65..410a92ab1980b 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java @@ -97,7 +97,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ValueType.OBJECT); - PARSER.declareInt(ReindexRequest::setSize, new ParseField("size")); + PARSER.declareInt(RestReindexAction::setMaxDocsValidateIdentical, new ParseField("max_docs", "size")); PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p)), new ParseField("script"), ValueType.OBJECT); PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts")); diff --git a/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java b/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java index 8def6dbb40316..25e44e392c43a 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java +++ b/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java @@ -121,7 +121,7 @@ public void testUpdateByQuery() { new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("source_index") .filter(QueryBuilders.termQuery("level", "awesome")) - .size(1000) + .maxDocs(1000) .script(new Script(ScriptType.INLINE, "ctx._source.awesome = 'absolutely'", "painless", @@ -144,7 +144,7 @@ public void testUpdateByQuery() { UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("source_index") - .size(100) + .maxDocs(100) .source() .addSort("cat", SortOrder.DESC); BulkByScrollResponse response = updateByQuery.get(); 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 43764bf25fcbf..97c4f7bb8defd 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 @@ -59,7 +59,7 @@ public void testFiltering() throws Exception { assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), 2); // Limit with size - copy = reindex().source("source").destination("dest_size_one", "type").size(1).refresh(true); + copy = reindex().source("source").destination("dest_size_one", "type").maxDocs(1).refresh(true); assertThat(copy.get(), matcher().created(1)); assertHitCount(client().prepareSearch("dest_size_one").setSize(0).get(), 1); } @@ -86,7 +86,7 @@ public void testCopyMany() throws Exception { copy = reindex().source("source").destination("dest_half", "type").refresh(true); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); - copy.size(half); // The real "size" of the request. + copy.maxDocs(half); // The real "size" of the request. assertThat(copy.get(), matcher().created(half).batches(half, 5)); assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), half); } @@ -116,7 +116,7 @@ public void testCopyManyWithSlices() throws Exception { copy = reindex().source("source").destination("dest_half", "type").refresh(true).setSlices(slices); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); - copy.size(half); // The real "size" of the request. + copy.maxDocs(half); // The real "size" of the request. BulkByScrollResponse response = copy.get(); assertThat(response, matcher().created(lessThanOrEqualTo((long) half)).slices(hasSize(expectedSlices))); assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), response.getCreated()); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java index 788fad3210037..f9eb866365a3b 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java @@ -25,8 +25,8 @@ import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; - import org.junit.Before; + import java.io.IOException; import static java.util.Collections.emptyList; @@ -58,7 +58,7 @@ public void testTypeInPath() throws IOException { public void testParseEmpty() throws IOException { DeleteByQueryRequest request = action.buildRequest(new FakeRestRequest.Builder(new NamedXContentRegistry(emptyList())).build()); - assertEquals(AbstractBulkByScrollRequest.SIZE_ALL_MATCHES, request.getSize()); + assertEquals(AbstractBulkByScrollRequest.MAX_DOCS_ALL_MATCHES, request.getMaxDocs()); assertEquals(AbstractBulkByScrollRequest.DEFAULT_SCROLL_SIZE, request.getSearchRequest().source().size()); } } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java index b5333226bb92e..ce6a3b6b40672 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java @@ -25,8 +25,8 @@ import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; - import org.junit.Before; + import java.io.IOException; import static java.util.Collections.emptyList; @@ -59,7 +59,7 @@ public void testTypeInPath() throws IOException { public void testParseEmpty() throws IOException { UpdateByQueryRequest request = action.buildRequest(new FakeRestRequest.Builder(new NamedXContentRegistry(emptyList())).build()); - assertEquals(AbstractBulkByScrollRequest.SIZE_ALL_MATCHES, request.getSize()); + assertEquals(AbstractBulkByScrollRequest.MAX_DOCS_ALL_MATCHES, request.getMaxDocs()); assertEquals(AbstractBulkByScrollRequest.DEFAULT_SCROLL_SIZE, request.getSearchRequest().source().size()); } } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RoundTripTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RoundTripTests.java index ab1968a2e3582..d0230eca25126 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RoundTripTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RoundTripTests.java @@ -107,7 +107,11 @@ private void randomRequest(AbstractBulkByScrollRequest request) { request.getSearchRequest().indices("test"); request.getSearchRequest().source().size(between(1, 1000)); if (randomBoolean()) { - request.setSize(between(1, Integer.MAX_VALUE)); + if (randomBoolean()) { + request.setMaxDocs(between(1, Integer.MAX_VALUE)); + } else { + request.setSize(between(1, Integer.MAX_VALUE)); + } } request.setAbortOnVersionConflict(random().nextBoolean()); request.setRefresh(rarely()); diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml index ded91a095f611..a5c36ff905fb3 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml @@ -281,6 +281,11 @@ --- "Limit by size": + - skip: + version: " - 7.1.99" + reason: "deprecation warnings only emitted on 7.2+" + features: warnings + - do: index: index: twitter @@ -295,6 +300,8 @@ indices.refresh: {} - do: + warnings: + - Deprecated field [size] used, expected [max_docs] instead delete_by_query: index: twitter size: 1 @@ -318,6 +325,92 @@ - match: {count: 1} +--- +"Limit by size pre 7.2": + - skip: + version: "7.2.0 - " + reason: "7.2 should use max_docs or get deprecation warning" + + - do: + index: + index: twitter + id: 1 + body: { "user": "kimchy" } + - do: + index: + index: twitter + id: 2 + body: { "user": "kimchy" } + - do: + indices.refresh: {} + + - do: + delete_by_query: + index: twitter + size: 1 + body: + query: + match_all: {} + + - match: {deleted: 1} + - match: {version_conflicts: 0} + - match: {batches: 1} + - match: {failures: []} + - match: {throttled_millis: 0} + - gte: { took: 0 } + + - do: + indices.refresh: {} + + - do: + count: + index: twitter + + - match: {count: 1} + +--- +"Limit by max_docs": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: twitter + id: 1 + body: { "user": "kimchy" } + - do: + index: + index: twitter + id: 2 + body: { "user": "kimchy" } + - do: + indices.refresh: {} + + - do: + delete_by_query: + index: twitter + max_docs: 1 + body: + query: + match_all: {} + + - match: {deleted: 1} + - match: {version_conflicts: 0} + - match: {batches: 1} + - match: {failures: []} + - match: {throttled_millis: 0} + - gte: { took: 0 } + + - do: + indices.refresh: {} + + - do: + count: + index: twitter + + - match: {count: 1} + --- "Can override scroll_size": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/20_validation.yml b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/20_validation.yml index 3caa8c4b43405..2a59dd14fb743 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/20_validation.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/20_validation.yml @@ -38,7 +38,7 @@ id: 1 body: { "text": "test" } - do: - catch: /\[size\] parameter cannot be negative, found \[-4\]/ + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ delete_by_query: index: test size: -4 @@ -46,6 +46,47 @@ query: match_all: {} +--- +"invalid max_docs fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ + delete_by_query: + index: test + max_docs: -4 + body: + query: + match_all: {} + +--- +"both max_docs and size fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] set to two different values \[4\] and \[5\]/ + delete_by_query: + index: test + size: 4 + max_docs: 5 + body: + query: + match_all: {} + --- "invalid scroll_size fails": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml index d45b14a1edc5f..be8359da02dd7 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml @@ -102,7 +102,7 @@ id: 1 body: { "text": "test" } - do: - catch: /\[size\] parameter cannot be negative, found \[-4\]/ + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ reindex: body: source: @@ -111,6 +111,49 @@ index: dest size: -4 +--- +"invalid max_docs fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ + reindex: + body: + source: + index: test + dest: + index: dest + max_docs: -4 + +--- +"both max_docs and size fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] set to two different values \[4\] and \[5\]/ + reindex: + body: + source: + index: test + dest: + index: dest + size: 4 + max_docs: 5 + --- "requests_per_second cannot be an empty string": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml index dff24e4413368..59d1eebf8a971 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml @@ -33,6 +33,56 @@ --- "Sorting and size combined": + - skip: + version: " - 7.1.99" + reason: "deprecation warnings only emitted on 7.2+" + features: warnings + + - do: + index: + index: test + id: 1 + body: { "order": 1 } + - do: + index: + index: test + id: 2 + body: { "order": 2 } + - do: + indices.refresh: {} + + - do: + warnings: + - Deprecated field [size] used, expected [max_docs] instead + reindex: + refresh: true + body: + size: 1 + source: + index: test + sort: order + dest: + index: target + + - do: + search: + rest_total_hits_as_int: true + index: target + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: target + q: order:1 + - match: { hits.total: 1 } + +--- +"Sorting and size combined pre 7.2": + - skip: + version: "7.2.0 - " + reason: "7.2 should use max_docs or get deprecation warning" + - do: index: index: test @@ -69,3 +119,46 @@ index: target q: order:1 - match: { hits.total: 1 } + +--- +"Sorting and max_docs combined": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "order": 1 } + - do: + index: + index: test + id: 2 + body: { "order": 2 } + - do: + indices.refresh: {} + + - do: + reindex: + refresh: true + body: + max_docs: 1 + source: + index: test + sort: order + dest: + index: target + + - do: + search: + rest_total_hits_as_int: true + index: target + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: target + q: order:1 + - match: { hits.total: 1 } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml index 65d6438e75d28..744d7b1783c0c 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml @@ -219,6 +219,10 @@ --- "Reindex from remote with size": + - skip: + version: "7.2.0 - " + reason: "7.2 should use max_docs or get deprecation warning" + - do: index: index: source @@ -279,6 +283,72 @@ metric: search - match: {indices.source.total.search.open_contexts: 0} +--- +"Reindex from remote with max_docs": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: source + id: 1 + body: { "text": "test" } + refresh: true + - do: + index: + index: source + id: 2 + body: { "text": "test" } + refresh: true + + # Fetch the http host. We use the host of the master because we know there will always be a master. + - do: + cluster.state: {} + - set: { master_node: master } + - do: + nodes.info: + metric: [ http ] + - is_true: nodes.$master.http.publish_address + - set: {nodes.$master.http.publish_address: host} + - do: + reindex: + refresh: true + body: + max_docs: 1 + source: + remote: + host: http://${host} + index: source + dest: + index: dest + - match: {created: 1} + - match: {updated: 0} + - match: {version_conflicts: 0} + - match: {batches: 1} + - match: {failures: []} + - match: {throttled_millis: 0} + - gte: { took: 0 } + - is_false: task + - is_false: deleted + + - do: + search: + rest_total_hits_as_int: true + index: dest + body: + query: + match: + text: test + - match: {hits.total: 1} + + # Make sure reindex closed all the scroll contexts + - do: + indices.stats: + index: source + metric: search + - match: {indices.source.total.search.open_contexts: 0} + --- "Reindex from remote with broken query": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml index 40119f22abb5b..d0ef1914f0c73 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml @@ -219,6 +219,11 @@ --- "Limit by size": + - skip: + version: " - 7.1.99" + reason: "deprecation warnings only emitted on 7.2+" + features: warnings + - do: index: index: twitter @@ -233,6 +238,8 @@ indices.refresh: {} - do: + warnings: + - Deprecated field [size] used, expected [max_docs] instead update_by_query: index: twitter size: 1 @@ -243,6 +250,66 @@ - match: {throttled_millis: 0} - gte: { took: 0 } +--- +"Limit by size pre 7.2": + - skip: + version: "7.2.0 - " + reason: "7.2 should use max_docs or get deprecation warning" + + - do: + index: + index: twitter + id: 1 + body: { "user": "kimchy" } + - do: + index: + index: twitter + id: 2 + body: { "user": "kimchy" } + - do: + indices.refresh: {} + + - do: + update_by_query: + index: twitter + size: 1 + - match: {updated: 1} + - match: {version_conflicts: 0} + - match: {batches: 1} + - match: {failures: []} + - match: {throttled_millis: 0} + - gte: { took: 0 } + +--- +"Limit by max_docs": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: twitter + id: 1 + body: { "user": "kimchy" } + - do: + index: + index: twitter + id: 2 + body: { "user": "kimchy" } + - do: + indices.refresh: {} + + - do: + update_by_query: + index: twitter + max_docs: 1 + - match: {updated: 1} + - match: {version_conflicts: 0} + - match: {batches: 1} + - match: {failures: []} + - match: {throttled_millis: 0} + - gte: { took: 0 } + --- "Can override scroll_size": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml index b6823f88c15fc..c74ffbef0ce31 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml @@ -19,11 +19,49 @@ id: 1 body: { "text": "test" } - do: - catch: /\[size\] parameter cannot be negative, found \[-4\]/ + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ update_by_query: index: test size: -4 +--- +"invalid max_docs fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ + update_by_query: + index: test + max_docs: -4 + +--- +"both max_docs and size fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] set to two different values \[4\] and \[5\]/ + delete_by_query: + index: test + size: 4 + max_docs: 5 + body: + query: + match_all: {} + --- "invalid scroll_size fails": - do: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query.json b/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query.json index 37b88e0f24d93..79693f8f1220b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query.json @@ -99,7 +99,11 @@ }, "size": { "type" : "number", - "description" : "Number of hits to return (default: 10)" + "description" : "Deprecated, please use `max_docs` instead" + }, + "max_docs": { + "type" : "number", + "description" : "Maximum number of documents to process (default: all documents)" }, "sort": { "type" : "list", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query.json b/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query.json index bdb4c565bd965..8be5d1b6f0830 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query.json @@ -103,7 +103,11 @@ }, "size": { "type" : "number", - "description" : "Number of hits to return (default: 10)" + "description" : "Deprecated, please use `max_docs` instead" + }, + "max_docs": { + "type" : "number", + "description" : "Maximum number of documents to process (default: all documents)" }, "sort": { "type" : "list", diff --git a/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java b/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java index add8eb6b668ae..f219bc975a563 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java @@ -42,7 +42,12 @@ public abstract class AbstractBulkByScrollRequest> extends ActionRequest { - public static final int SIZE_ALL_MATCHES = -1; + public static final int MAX_DOCS_ALL_MATCHES = -1; + /** + * @deprecated please use MAX_DOCS_ALL_MATCHES instead. + */ + @Deprecated + public static final int SIZE_ALL_MATCHES = MAX_DOCS_ALL_MATCHES; public static final TimeValue DEFAULT_SCROLL_TIMEOUT = timeValueMinutes(5); public static final int DEFAULT_SCROLL_SIZE = 1000; @@ -59,7 +64,7 @@ public abstract class AbstractBulkByScrollRequest 0)) { + if (false == (maxDocs == -1 || maxDocs > 0)) { e = addValidationError( - "size should be greater than 0 if the request is limited to some number of documents or -1 if it isn't but it was [" - + size + "]", + "maxDocs should be greater than 0 if the request is limited to some number of documents or -1 if it isn't but it was [" + + maxDocs + "]", e); } if (searchRequest.source().slice() != null && slices != DEFAULT_SLICES) { @@ -166,20 +171,41 @@ public ActionRequestValidationException validate() { /** * Maximum number of processed documents. Defaults to -1 meaning process all * documents. + * @deprecated please use getMaxDocs() instead. */ + @Deprecated public int getSize() { - return size; + return getMaxDocs(); } /** * Maximum number of processed documents. Defaults to -1 meaning process all * documents. + * + * @deprecated please use setMaxDocs(int) instead. */ + @Deprecated public Self setSize(int size) { - if (size < 0) { - throw new IllegalArgumentException("[size] parameter cannot be negative, found [" + size + "]"); + return setMaxDocs(size); + } + + /** + * Maximum number of processed documents. Defaults to -1 meaning process all + * documents. + */ + public int getMaxDocs() { + return maxDocs; + } + + /** + * Maximum number of processed documents. Defaults to -1 meaning process all + * documents. + */ + public Self setMaxDocs(int maxDocs) { + if (maxDocs < 0) { + throw new IllegalArgumentException("[max_docs] parameter cannot be negative, found [" + maxDocs + "]"); } - this.size = size; + this.maxDocs = maxDocs; return self(); } @@ -404,10 +430,10 @@ protected Self doForSlice(Self request, TaskId slicingTask, int totalSlices) { .setRequestsPerSecond(requestsPerSecond / totalSlices) // Sub requests don't have workers .setSlices(1); - if (size != -1) { - // Size is split between workers. This means the size might round + if (maxDocs != MAX_DOCS_ALL_MATCHES) { + // maxDocs is split between workers. This means the maxDocs might round // down! - request.setSize(size == SIZE_ALL_MATCHES ? SIZE_ALL_MATCHES : size / totalSlices); + request.setMaxDocs(maxDocs / totalSlices); } // Set the parent task so this task is cancelled if we cancel the parent request.setParentTask(slicingTask); @@ -425,7 +451,7 @@ public void readFrom(StreamInput in) throws IOException { super.readFrom(in); searchRequest = new SearchRequest(in); abortOnVersionConflict = in.readBoolean(); - size = in.readVInt(); + maxDocs = in.readVInt(); refresh = in.readBoolean(); timeout = in.readTimeValue(); activeShardCount = ActiveShardCount.readFrom(in); @@ -440,7 +466,7 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); searchRequest.writeTo(out); out.writeBoolean(abortOnVersionConflict); - out.writeVInt(size); + out.writeVInt(maxDocs); out.writeBoolean(refresh); out.writeTimeValue(timeout); activeShardCount.writeTo(out); diff --git a/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestBuilder.java b/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestBuilder.java index a14ef850c5079..3778916c7caae 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestBuilder.java @@ -67,10 +67,22 @@ public Self filter(QueryBuilder filter) { } /** - * The maximum number of documents to attempt. + * Maximum number of processed documents. Defaults to processing all + * documents. + * @deprecated please use maxDocs(int) instead. */ + @Deprecated public Self size(int size) { - request.setSize(size); + return maxDocs(size); + } + + + /** + * Maximum number of processed documents. Defaults to processing all + * documents. + */ + public Self maxDocs(int maxDocs) { + request.setMaxDocs(maxDocs); return self(); } diff --git a/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java b/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java index de171e88fbca1..4dd243220b1ba 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java @@ -322,8 +322,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } { // Other fields - if (getSize() != -1 || getSize() > 0) { - builder.field("size", getSize()); + if (getMaxDocs() != -1 || getMaxDocs() > 0) { + builder.field("max_docs", getMaxDocs()); } if (getScript() != null) { builder.field("script", getScript()); diff --git a/server/src/test/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestTestCase.java b/server/src/test/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestTestCase.java index 143e2416b8880..21f250cb1ae79 100644 --- a/server/src/test/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestTestCase.java +++ b/server/src/test/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequestTestCase.java @@ -42,7 +42,11 @@ public void testForSlice() { original.setRequestsPerSecond( randomBoolean() ? Float.POSITIVE_INFINITY : randomValueOtherThanMany(r -> r < 0, ESTestCase::randomFloat)); if (randomBoolean()) { - original.setSize(between(0, Integer.MAX_VALUE)); + if (randomBoolean()) { + original.setMaxDocs(between(0, Integer.MAX_VALUE)); + } else { + original.setSize(between(0, Integer.MAX_VALUE)); + } } // it's not important how many slices there are, we just need a number for forSlice @@ -64,8 +68,10 @@ public void testForSlice() { assertEquals("slice requests always have a single worker", 1, forSliced.getSlices()); assertEquals("requests_per_second is split between all workers", original.getRequestsPerSecond() / actualSlices, forSliced.getRequestsPerSecond(), Float.MIN_NORMAL); - assertEquals("size is split evenly between all workers", original.getSize() == AbstractBulkByScrollRequest.SIZE_ALL_MATCHES - ? AbstractBulkByScrollRequest.SIZE_ALL_MATCHES : original.getSize() / actualSlices, forSliced.getSize()); + assertEquals("max_docs is split evenly between all workers", + original.getMaxDocs() == AbstractBulkByScrollRequest.MAX_DOCS_ALL_MATCHES + ? AbstractBulkByScrollRequest.MAX_DOCS_ALL_MATCHES : original.getMaxDocs() / actualSlices, + forSliced.getMaxDocs()); assertEquals(slicingTask, forSliced.getParentTask()); extraForSliceAssertions(original, forSliced); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteForecastAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteForecastAction.java index 2575e71444447..c0783ac8d3c5c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteForecastAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteForecastAction.java @@ -197,7 +197,7 @@ private static Set parseForecastsFromSearch(SearchResponse private DeleteByQueryRequest buildDeleteByQuery(String jobId, List forecastsToDelete) { DeleteByQueryRequest request = new DeleteByQueryRequest() .setAbortOnVersionConflict(false) //since these documents are not updated, a conflict just means it was deleted previously - .setSize(MAX_FORECAST_TO_SEARCH) + .setMaxDocs(MAX_FORECAST_TO_SEARCH) .setSlices(5); request.indices(AnomalyDetectorsIndex.jobResultsAliasedName(jobId)); From 8068102fc31324ad4e8af86560cb82c55d313713 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 20 May 2019 08:54:41 +0200 Subject: [PATCH 2/6] max_docs in body and URL Allow specifying max_docs in both body and URL for all 3 of reindex, update by query and delete by query. --- .../AbstractBaseReindexRestHandler.java | 5 ++ .../AbstractBulkByQueryRestHandler.java | 4 -- .../reindex/RestDeleteByQueryAction.java | 1 + .../reindex/RestUpdateByQueryAction.java | 1 + .../test/delete_by_query/10_basic.yml | 46 +++++++++++++++++- .../test/reindex/20_validation.yml | 47 ++++++++++++++++++- .../rest-api-spec/test/reindex/30_search.yml | 37 ++++++++++++++- .../test/update_by_query/10_basic.yml | 36 +++++++++++++- .../test/update_by_query/20_validation.yml | 43 ++++++++++++++++- .../resources/rest-api-spec/api/reindex.json | 4 ++ 10 files changed, 213 insertions(+), 11 deletions(-) diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java index ebc07811a80d8..8111aac39451b 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java @@ -105,6 +105,11 @@ protected Request setCommonOptions(RestRequest restRequest, Request request) { if (requestsPerSecond != null) { request.setRequestsPerSecond(requestsPerSecond); } + + if (restRequest.hasParam("max_docs")) { + setMaxDocsValidateIdentical(request, restRequest.paramAsInt("max_docs", -1)); + } + return request; } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java index ab8898d15cc04..240ccde350532 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java @@ -58,10 +58,6 @@ protected void parseInternalRequest(Request internal, RestRequest restRequest, searchRequest.source().size(restRequest.paramAsInt("scroll_size", searchRequest.source().size())); - if (restRequest.hasParam("max_docs")) { - setMaxDocsValidateIdentical(internal, restRequest.paramAsInt("max_docs", -1)); - } - String conflicts = restRequest.param("conflicts"); if (conflicts != null) { internal.setConflicts(conflicts); diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java index 5d4d140131a14..74e600f32cd75 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java @@ -58,6 +58,7 @@ protected DeleteByQueryRequest buildRequest(RestRequest request) throws IOExcept Map> consumers = new HashMap<>(); consumers.put("conflicts", o -> internal.setConflicts((String) o)); + consumers.put("max_docs", s -> setMaxDocsValidateIdentical(internal, ((Number) s).intValue())); parseInternalRequest(internal, request, consumers); diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java index 121f8c372c59c..ea715aee7bd3a 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java @@ -66,6 +66,7 @@ protected UpdateByQueryRequest buildRequest(RestRequest request) throws IOExcept Map> consumers = new HashMap<>(); consumers.put("conflicts", o -> internal.setConflicts((String) o)); consumers.put("script", o -> internal.setScript(parseScript(o))); + consumers.put("max_docs", s -> setMaxDocsValidateIdentical(internal, ((Number) s).intValue())); parseInternalRequest(internal, request, consumers); diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml index a5c36ff905fb3..beb8486a73c27 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml @@ -369,7 +369,7 @@ - match: {count: 1} --- -"Limit by max_docs": +"Limit by max_docs in URL": - skip: version: " - 7.1.99" reason: "max_docs introduced in 7.2.0" @@ -411,6 +411,50 @@ - match: {count: 1} +--- +"Limit by max_docs in body": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: twitter + id: 1 + body: { "user": "kimchy" } + - do: + index: + index: twitter + id: 2 + body: { "user": "kimchy" } + - do: + indices.refresh: {} + + - do: + delete_by_query: + index: twitter + body: + max_docs: 1 + query: + match: + user: "kimchy" + + - match: {deleted: 1} + - match: {version_conflicts: 0} + - match: {batches: 1} + - match: {failures: []} + - match: {throttled_millis: 0} + - gte: { took: 0 } + + - do: + indices.refresh: {} + + - do: + count: + index: twitter + + - match: {count: 1} + --- "Can override scroll_size": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml index be8359da02dd7..e9b5ab7c1292b 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml @@ -112,7 +112,7 @@ size: -4 --- -"invalid max_docs fails": +"invalid max_docs in body fails": - skip: version: " - 7.1.99" reason: "max_docs introduced in 7.2.0" @@ -133,7 +133,28 @@ max_docs: -4 --- -"both max_docs and size fails": +"invalid max_docs in URL fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ + reindex: + max_docs: -4 + body: + source: + index: test + dest: + index: dest + +--- +"inconsistent max_docs and size fails": - skip: version: " - 7.1.99" reason: "max_docs introduced in 7.2.0" @@ -154,6 +175,28 @@ size: 4 max_docs: 5 +--- +"inconsistent max_docs in body and max_docs in URL fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] set to two different values \[4\] and \[5\]/ + reindex: + max_docs: 5 + body: + source: + index: test + dest: + index: dest + max_docs: 4 + --- "requests_per_second cannot be an empty string": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml index 59d1eebf8a971..5a95612740455 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml @@ -121,7 +121,7 @@ - match: { hits.total: 1 } --- -"Sorting and max_docs combined": +"Sorting and max_docs in body combined": - skip: version: " - 7.1.99" reason: "max_docs introduced in 7.2.0" @@ -162,3 +162,38 @@ index: target q: order:1 - match: { hits.total: 1 } + +--- +"max_docs in URL": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "value": 17 } + - do: + index: + index: test + id: 2 + body: { "value": 17 } + - do: + indices.refresh: {} + + - do: + reindex: + refresh: true + max_docs: 1 + body: + source: + index: test + dest: + index: target + + - do: + search: + rest_total_hits_as_int: true + index: target + - match: { hits.total: 1 } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml index d0ef1914f0c73..8f3d20535c970 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/10_basic.yml @@ -281,7 +281,7 @@ - gte: { took: 0 } --- -"Limit by max_docs": +"Limit by max_docs in URL": - skip: version: " - 7.1.99" reason: "max_docs introduced in 7.2.0" @@ -310,6 +310,40 @@ - match: {throttled_millis: 0} - gte: { took: 0 } +--- +"Limit by max_docs in body": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: twitter + id: 1 + body: { "user": "kimchy" } + - do: + index: + index: twitter + id: 2 + body: { "user": "kimchy" } + - do: + indices.refresh: {} + + - do: + update_by_query: + index: twitter + body: + max_docs: 1 + query: + match: + user: "kimchy" + - match: {updated: 1} + - match: {version_conflicts: 0} + - match: {batches: 1} + - match: {failures: []} + - match: {throttled_millis: 0} + - gte: { took: 0 } + --- "Can override scroll_size": - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml index c74ffbef0ce31..45231473ea6c3 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml @@ -25,7 +25,7 @@ size: -4 --- -"invalid max_docs fails": +"invalid max_docs in URL fails": - skip: version: " - 7.1.99" reason: "max_docs introduced in 7.2.0" @@ -42,7 +42,25 @@ max_docs: -4 --- -"both max_docs and size fails": +"invalid max_docs in body fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/ + update_by_query: + index: test + body: + max_docs: -4 + +--- +"inconsistent max_docs and size fails": - skip: version: " - 7.1.99" reason: "max_docs introduced in 7.2.0" @@ -62,6 +80,27 @@ query: match_all: {} +--- +"inconsistent max_docs in body and max_docs in URL fails": + - skip: + version: " - 7.1.99" + reason: "max_docs introduced in 7.2.0" + + - do: + index: + index: test + id: 1 + body: { "text": "test" } + - do: + catch: /\[max_docs\] set to two different values \[4\] and \[5\]/ + delete_by_query: + index: test + max_docs: 5 + body: + max_docs: 4 + query: + match_all: {} + --- "invalid scroll_size fails": - do: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/reindex.json b/rest-api-spec/src/main/resources/rest-api-spec/api/reindex.json index e85eadb5bc41e..34449cf9c6f41 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/reindex.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/reindex.json @@ -39,6 +39,10 @@ "type": "number", "default": 1, "description": "The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks." + }, + "max_docs": { + "type" : "number", + "description" : "Maximum number of documents to process (default: all documents)" } } }, From b03bba483323eaea398d27fad6c2d8188410e018 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 20 May 2019 09:01:16 +0200 Subject: [PATCH 3/6] quote maxDocs --- docs/java-rest/high-level/document/delete-by-query.asciidoc | 2 +- docs/java-rest/high-level/document/update-by-query.asciidoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/java-rest/high-level/document/delete-by-query.asciidoc b/docs/java-rest/high-level/document/delete-by-query.asciidoc index a768dff4c5010..f4ef87741e639 100644 --- a/docs/java-rest/high-level/document/delete-by-query.asciidoc +++ b/docs/java-rest/high-level/document/delete-by-query.asciidoc @@ -39,7 +39,7 @@ include-tagged::{doc-tests-file}[{api}-request-query] -------------------------------------------------- <1> Only copy documents which have field `user` set to `kimchy` -It’s also possible to limit the number of processed documents by setting maxDocs. +It’s also possible to limit the number of processed documents by setting `maxDocs`. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- diff --git a/docs/java-rest/high-level/document/update-by-query.asciidoc b/docs/java-rest/high-level/document/update-by-query.asciidoc index 80c5063c4b109..26a6bc362b191 100644 --- a/docs/java-rest/high-level/document/update-by-query.asciidoc +++ b/docs/java-rest/high-level/document/update-by-query.asciidoc @@ -40,7 +40,7 @@ include-tagged::{doc-tests-file}[{api}-request-query] -------------------------------------------------- <1> Only copy documents which have field `user` set to `kimchy` -It’s also possible to limit the number of processed documents by setting maxDocs. +It’s also possible to limit the number of processed documents by setting `maxDocs`. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- From 391858edb2c477c03ed9539c394082cb5305f6b6 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 20 May 2019 09:05:26 +0200 Subject: [PATCH 4/6] Comment update --- .../java/org/elasticsearch/index/reindex/ReindexBasicTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 97c4f7bb8defd..7441b01d3b93c 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 @@ -58,7 +58,7 @@ public void testFiltering() throws Exception { assertThat(copy.get(), matcher().created(2)); assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), 2); - // Limit with size + // Limit with maxDocs copy = reindex().source("source").destination("dest_size_one", "type").maxDocs(1).refresh(true); assertThat(copy.get(), matcher().created(1)); assertHitCount(client().prepareSearch("dest_size_one").setSize(0).get(), 1); From 510d90c418a2bb847391fadecd218ea1a07a6553 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 20 May 2019 09:09:13 +0200 Subject: [PATCH 5/6] Remove comments Remove comments explaining which size is set (no longer confusing). --- .../org/elasticsearch/index/reindex/ReindexBasicTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 7441b01d3b93c..9159f39708f24 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 @@ -86,7 +86,7 @@ public void testCopyMany() throws Exception { copy = reindex().source("source").destination("dest_half", "type").refresh(true); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); - copy.maxDocs(half); // The real "size" of the request. + copy.maxDocs(half); assertThat(copy.get(), matcher().created(half).batches(half, 5)); assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), half); } @@ -116,7 +116,7 @@ public void testCopyManyWithSlices() throws Exception { copy = reindex().source("source").destination("dest_half", "type").refresh(true).setSlices(slices); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); - copy.maxDocs(half); // The real "size" of the request. + copy.maxDocs(half); BulkByScrollResponse response = copy.get(); assertThat(response, matcher().created(lessThanOrEqualTo((long) half)).slices(hasSize(expectedSlices))); assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), response.getCreated()); From 687674ef02e5fba484a4ba355cfd5a22faa1abe2 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 20 May 2019 09:24:04 +0200 Subject: [PATCH 6/6] Remove unreachable condition. --- .../java/org/elasticsearch/index/reindex/ReindexRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java b/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java index 4dd243220b1ba..3aa501819b63b 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java @@ -322,7 +322,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } { // Other fields - if (getMaxDocs() != -1 || getMaxDocs() > 0) { + if (getMaxDocs() != -1) { builder.field("max_docs", getMaxDocs()); } if (getScript() != null) {