From c1bcbc048779c8af6b45d2dd104e19e1483f63d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 21 Sep 2018 11:02:10 +0200 Subject: [PATCH 1/3] HLRC: Add throttling for update & delete-by-query This change adds throttling to the update-by-query and delete-by-query cases similar to throttling for reindex. This mostly means additional methods on the client class itself, since the request hits the same RestHandler, just with slightly different endpoints, and also the return values are similar. Also updating the docs to reflect this. --- .../client/RequestConverters.java | 16 ++- .../client/RestHighLevelClient.java | 62 +++++++++- .../java/org/elasticsearch/client/CrudIT.java | 111 ++++++++++++++++-- .../client/RequestConvertersTests.java | 22 +++- .../documentation/CRUDDocumentationIT.java | 30 +++-- ...ethrottle.asciidoc => rethrottle.asciidoc} | 39 ++++-- .../high-level/supported-apis.asciidoc | 4 +- .../api/delete_by_query_rethrottle.json | 25 ++++ .../api/update_by_query_rethrottle.json | 25 ++++ 9 files changed, 288 insertions(+), 46 deletions(-) rename docs/java-rest/high-level/document/{reindex-rethrottle.asciidoc => rethrottle.asciidoc} (65%) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json 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 901f564075875..9c461a404cf8f 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 @@ -530,8 +530,20 @@ static Request deleteByQuery(DeleteByQueryRequest deleteByQueryRequest) throws I return request; } - static Request rethrottle(RethrottleRequest rethrottleRequest) throws IOException { - String endpoint = new EndpointBuilder().addPathPart("_reindex").addPathPart(rethrottleRequest.getTaskId().toString()) + static Request rethrottleReindex(RethrottleRequest rethrottleRequest) { + return rethrottle(rethrottleRequest, "_reindex"); + } + + static Request rethrottleUpdateByQuery(RethrottleRequest rethrottleRequest) { + return rethrottle(rethrottleRequest, "_update_by_query"); + } + + static Request rethrottleDeleteByQuery(RethrottleRequest rethrottleRequest) { + return rethrottle(rethrottleRequest, "_delete_by_query"); + } + + private static Request rethrottle(RethrottleRequest rethrottleRequest, String firstPathPart) { + String endpoint = new EndpointBuilder().addPathPart(firstPathPart).addPathPart(rethrottleRequest.getTaskId().toString()) .addPathPart("_rethrottle").build(); Request request = new Request(HttpPost.METHOD_NAME, endpoint); Params params = new Params(request) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index 176436ce458a7..dfb3182a837b1 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -516,6 +516,62 @@ public final void deleteByQueryAsync(DeleteByQueryRequest deleteByQueryRequest, ); } + /** + * Executes a delete by query rethrottle request. + * See + * Delete By Query API on elastic.co + * @param rethrottleRequest the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @return the response + * @throws IOException in case there is a problem sending the request or parsing back the response + */ + public final ListTasksResponse deleteByQueryRethrottle(RethrottleRequest rethrottleRequest, RequestOptions options) throws IOException { + return performRequestAndParseEntity(rethrottleRequest, RequestConverters::rethrottleDeleteByQuery, options, + ListTasksResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously execute an delete by query rethrottle request. + * See + * Delete By Query API on elastic.co + * @param rethrottleRequest the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @param listener the listener to be notified upon request completion + */ + public final void deleteByQueryRethrottleAsync(RethrottleRequest rethrottleRequest, RequestOptions options, + ActionListener listener) { + performRequestAsyncAndParseEntity(rethrottleRequest, RequestConverters::rethrottleDeleteByQuery, options, + ListTasksResponse::fromXContent, listener, emptySet()); + } + + /** + * Executes a update by query rethrottle request. + * See + * Update By Query API on elastic.co + * @param rethrottleRequest the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @return the response + * @throws IOException in case there is a problem sending the request or parsing back the response + */ + public final ListTasksResponse updateByQueryRethrottle(RethrottleRequest rethrottleRequest, RequestOptions options) throws IOException { + return performRequestAndParseEntity(rethrottleRequest, RequestConverters::rethrottleUpdateByQuery, options, + ListTasksResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously execute an update by query rethrottle request. + * See + * Update By Query API on elastic.co + * @param rethrottleRequest the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @param listener the listener to be notified upon request completion + */ + public final void updateByQueryRethrottleAsync(RethrottleRequest rethrottleRequest, RequestOptions options, + ActionListener listener) { + performRequestAsyncAndParseEntity(rethrottleRequest, RequestConverters::rethrottleUpdateByQuery, options, + ListTasksResponse::fromXContent, listener, emptySet()); + } + /** * Executes a reindex rethrottling request. * See the @@ -526,8 +582,8 @@ public final void deleteByQueryAsync(DeleteByQueryRequest deleteByQueryRequest, * @throws IOException in case there is a problem sending the request or parsing back the response */ public final ListTasksResponse reindexRethrottle(RethrottleRequest rethrottleRequest, RequestOptions options) throws IOException { - return performRequestAndParseEntity(rethrottleRequest, RequestConverters::rethrottle, options, ListTasksResponse::fromXContent, - emptySet()); + return performRequestAndParseEntity(rethrottleRequest, RequestConverters::rethrottleReindex, options, + ListTasksResponse::fromXContent, emptySet()); } /** @@ -540,7 +596,7 @@ public final ListTasksResponse reindexRethrottle(RethrottleRequest rethrottleReq */ public final void reindexRethrottleAsync(RethrottleRequest rethrottleRequest, RequestOptions options, ActionListener listener) { - performRequestAsyncAndParseEntity(rethrottleRequest, RequestConverters::rethrottle, options, ListTasksResponse::fromXContent, + performRequestAsyncAndParseEntity(rethrottleRequest, RequestConverters::rethrottleReindex, options, ListTasksResponse::fromXContent, listener, emptySet()); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java index 293e6b24a7b0d..73b8ebf381079 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java @@ -55,9 +55,11 @@ import org.elasticsearch.index.get.GetResult; import org.elasticsearch.index.query.IdsQueryBuilder; import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.elasticsearch.index.reindex.DeleteByQueryAction; import org.elasticsearch.index.reindex.DeleteByQueryRequest; import org.elasticsearch.index.reindex.ReindexAction; import org.elasticsearch.index.reindex.ReindexRequest; +import org.elasticsearch.index.reindex.UpdateByQueryAction; import org.elasticsearch.index.reindex.UpdateByQueryRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.script.Script; @@ -727,10 +729,7 @@ public void onFailure(Exception e) { } }); - TaskGroup taskGroupToRethrottle = findTaskToRethrottle(); - assertThat(taskGroupToRethrottle.getChildTasks(), empty()); - TaskId taskIdToRethrottle = taskGroupToRethrottle.getTaskInfo().getTaskId(); - + TaskId taskIdToRethrottle = findTaskToRethrottle(ReindexAction.NAME); float requestsPerSecond = 1000f; ListTasksResponse response = execute(new RethrottleRequest(taskIdToRethrottle, requestsPerSecond), highLevelClient()::reindexRethrottle, highLevelClient()::reindexRethrottleAsync); @@ -752,10 +751,10 @@ public void onFailure(Exception e) { } } - private TaskGroup findTaskToRethrottle() throws IOException { + private TaskId findTaskToRethrottle(String actionName) throws IOException { long start = System.nanoTime(); ListTasksRequest request = new ListTasksRequest(); - request.setActions(ReindexAction.NAME); + request.setActions(actionName); request.setDetailed(true); do { ListTasksResponse list = highLevelClient().tasks().list(request, RequestOptions.DEFAULT); @@ -766,13 +765,15 @@ private TaskGroup findTaskToRethrottle() throws IOException { // The parent task hasn't started yet continue; } - return list.getTaskGroups().get(0); + TaskGroup taskGroup = list.getTaskGroups().get(0); + assertThat(taskGroup.getChildTasks(), empty()); + return taskGroup.getTaskInfo().getTaskId(); } while (System.nanoTime() - start < TimeUnit.SECONDS.toNanos(10)); throw new AssertionError("Couldn't find tasks to rethrottle. Here are the running tasks " + highLevelClient().tasks().list(request, RequestOptions.DEFAULT)); } - public void testUpdateByQuery() throws IOException { + public void testUpdateByQuery() throws Exception { final String sourceIndex = "source1"; { // Prepare @@ -836,9 +837,53 @@ public void testUpdateByQuery() throws IOException { .getSourceAsMap().get("foo")) ); } + { + // test update-by-query rethrottling + UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest(); + updateByQueryRequest.indices(sourceIndex); + updateByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1").types("type")); + updateByQueryRequest.setRefresh(true); + + // this following settings are supposed to halt reindexing after first document + updateByQueryRequest.setBatchSize(1); + updateByQueryRequest.setRequestsPerSecond(0.00001f); + final CountDownLatch taskFinished = new CountDownLatch(1); + highLevelClient().updateByQueryAsync(updateByQueryRequest, RequestOptions.DEFAULT, new ActionListener() { + + @Override + public void onResponse(BulkByScrollResponse response) { + taskFinished.countDown(); + } + + @Override + public void onFailure(Exception e) { + fail(e.toString()); + } + }); + + TaskId taskIdToRethrottle = findTaskToRethrottle(UpdateByQueryAction.NAME); + float requestsPerSecond = 1000f; + ListTasksResponse response = execute(new RethrottleRequest(taskIdToRethrottle, requestsPerSecond), + highLevelClient()::updateByQueryRethrottle, highLevelClient()::updateByQueryRethrottleAsync); + assertThat(response.getTasks(), hasSize(1)); + assertEquals(taskIdToRethrottle, response.getTasks().get(0).getTaskId()); + assertThat(response.getTasks().get(0).getStatus(), instanceOf(RawTaskStatus.class)); + assertEquals(Float.toString(requestsPerSecond), + ((RawTaskStatus) response.getTasks().get(0).getStatus()).toMap().get("requests_per_second").toString()); + taskFinished.await(2, TimeUnit.SECONDS); + + // any rethrottling after the update-by-query is done performed with the same taskId should result in a failure + response = execute(new RethrottleRequest(taskIdToRethrottle, requestsPerSecond), + highLevelClient()::updateByQueryRethrottle, highLevelClient()::updateByQueryRethrottleAsync); + assertTrue(response.getTasks().isEmpty()); + assertFalse(response.getNodeFailures().isEmpty()); + assertEquals(1, response.getNodeFailures().size()); + assertEquals("Elasticsearch exception [type=resource_not_found_exception, reason=task [" + taskIdToRethrottle + "] is missing]", + response.getNodeFailures().get(0).getCause().getMessage()); + } } - public void testDeleteByQuery() throws IOException { + public void testDeleteByQuery() throws Exception { final String sourceIndex = "source1"; { // Prepare @@ -855,6 +900,8 @@ public void testDeleteByQuery() throws IOException { .source(Collections.singletonMap("foo", 1), XContentType.JSON)) .add(new IndexRequest(sourceIndex, "type", "2") .source(Collections.singletonMap("foo", 2), XContentType.JSON)) + .add(new IndexRequest(sourceIndex, "type", "3") + .source(Collections.singletonMap("foo", 3), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT ).status() @@ -878,10 +925,54 @@ public void testDeleteByQuery() throws IOException { assertEquals(0, bulkResponse.getBulkFailures().size()); assertEquals(0, bulkResponse.getSearchFailures().size()); assertEquals( - 1, + 2, highLevelClient().search(new SearchRequest(sourceIndex), RequestOptions.DEFAULT).getHits().totalHits ); } + { + // test delete-by-query rethrottling + DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(); + deleteByQueryRequest.indices(sourceIndex); + deleteByQueryRequest.setQuery(new IdsQueryBuilder().addIds("2", "3").types("type")); + deleteByQueryRequest.setRefresh(true); + + // this following settings are supposed to halt reindexing after first document + deleteByQueryRequest.setBatchSize(1); + deleteByQueryRequest.setRequestsPerSecond(0.00001f); + final CountDownLatch taskFinished = new CountDownLatch(1); + highLevelClient().deleteByQueryAsync(deleteByQueryRequest, RequestOptions.DEFAULT, new ActionListener() { + + @Override + public void onResponse(BulkByScrollResponse response) { + taskFinished.countDown(); + } + + @Override + public void onFailure(Exception e) { + fail(e.toString()); + } + }); + + TaskId taskIdToRethrottle = findTaskToRethrottle(DeleteByQueryAction.NAME); + float requestsPerSecond = 1000f; + ListTasksResponse response = execute(new RethrottleRequest(taskIdToRethrottle, requestsPerSecond), + highLevelClient()::deleteByQueryRethrottle, highLevelClient()::deleteByQueryRethrottleAsync); + assertThat(response.getTasks(), hasSize(1)); + assertEquals(taskIdToRethrottle, response.getTasks().get(0).getTaskId()); + assertThat(response.getTasks().get(0).getStatus(), instanceOf(RawTaskStatus.class)); + assertEquals(Float.toString(requestsPerSecond), + ((RawTaskStatus) response.getTasks().get(0).getStatus()).toMap().get("requests_per_second").toString()); + taskFinished.await(2, TimeUnit.SECONDS); + + // any rethrottling after the delete-by-query is done performed with the same taskId should result in a failure + response = execute(new RethrottleRequest(taskIdToRethrottle, requestsPerSecond), + highLevelClient()::deleteByQueryRethrottle, highLevelClient()::deleteByQueryRethrottleAsync); + assertTrue(response.getTasks().isEmpty()); + assertFalse(response.getNodeFailures().isEmpty()); + assertEquals(1, response.getNodeFailures().size()); + assertEquals("Elasticsearch exception [type=resource_not_found_exception, reason=task [" + taskIdToRethrottle + "] is missing]", + response.getNodeFailures().get(0).getCause().getMessage()); + } } public void testBulkProcessorIntegration() throws IOException { 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 5fce2f168fbc9..3801dfe71de9c 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 @@ -59,6 +59,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.unit.TimeValue; @@ -466,7 +467,7 @@ public void testDeleteByQuery() throws IOException { assertToXContentBody(deleteByQueryRequest, request.getEntity()); } - public void testRethrottle() throws IOException { + public void testRethrottle() { TaskId taskId = new TaskId(randomAlphaOfLength(10), randomIntBetween(1, 100)); RethrottleRequest rethrottleRequest; Float requestsPerSecond; @@ -480,11 +481,20 @@ public void testRethrottle() throws IOException { expectedParams.put(RethrottleRequest.REQUEST_PER_SECOND_PARAMETER, "-1"); } expectedParams.put("group_by", "none"); - Request request = RequestConverters.rethrottle(rethrottleRequest); - assertEquals("/_reindex/" + taskId + "/_rethrottle", request.getEndpoint()); - assertEquals(HttpPost.METHOD_NAME, request.getMethod()); - assertEquals(expectedParams, request.getParameters()); - assertNull(request.getEntity()); + List>> variants = new ArrayList<>(); + variants.add(new Tuple>("_reindex", () -> RequestConverters.rethrottleReindex(rethrottleRequest))); + variants.add(new Tuple>("_update_by_query", + () -> RequestConverters.rethrottleUpdateByQuery(rethrottleRequest))); + variants.add(new Tuple>("_delete_by_query", + () -> RequestConverters.rethrottleDeleteByQuery(rethrottleRequest))); + + for (Tuple> variant : variants) { + Request request = variant.v2().get(); + assertEquals("/" + variant.v1() + "/" + taskId + "/_rethrottle", request.getEndpoint()); + assertEquals(HttpPost.METHOD_NAME, request.getMethod()); + assertEquals(expectedParams, request.getParameters()); + assertNull(request.getEntity()); + } // test illegal RethrottleRequest values Exception e = expectThrows(NullPointerException.class, () -> new RethrottleRequest(null, 1.0f)); 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 85612147b464d..bc114128ed416 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 @@ -905,24 +905,32 @@ public void onFailure(Exception e) { } } - public void testReindexRethrottle() throws Exception { + @SuppressWarnings("unused") + public void testRethrottle() throws Exception { RestHighLevelClient client = highLevelClient(); TaskId taskId = new TaskId("oTUltX4IQMOUUVeiohTt8A:124"); { // tag::rethrottle-disable-request - RethrottleRequest rethrottleRequest = new RethrottleRequest(taskId); // <1> - client.reindexRethrottle(rethrottleRequest, RequestOptions.DEFAULT); + RethrottleRequest request = new RethrottleRequest(taskId); // <1> // end::rethrottle-disable-request } { // tag::rethrottle-request - RethrottleRequest rethrottleRequest = new RethrottleRequest(taskId, 100.0f); // <1> - client.reindexRethrottle(rethrottleRequest, RequestOptions.DEFAULT); + RethrottleRequest request = new RethrottleRequest(taskId, 100.0f); // <1> // end::rethrottle-request } - // tag::rethrottle-request-async + { + RethrottleRequest request = new RethrottleRequest(taskId); + // tag::rethrottle-request-execution + client.reindexRethrottle(request, RequestOptions.DEFAULT); // <1> + client.updateByQueryRethrottle(request, RequestOptions.DEFAULT); // <2> + client.deleteByQueryRethrottle(request, RequestOptions.DEFAULT); // <3> + // end::rethrottle-request-execution + } + + // tag::rethrottle-request-async-listener ActionListener listener = new ActionListener() { @Override public void onResponse(ListTasksResponse response) { @@ -934,15 +942,17 @@ public void onFailure(Exception e) { // <2> } }; - // end::rethrottle-request-async + // end::rethrottle-request-async-listener // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); + final CountDownLatch latch = new CountDownLatch(3); listener = new LatchedActionListener<>(listener, latch); - RethrottleRequest rethrottleRequest = new RethrottleRequest(taskId); + RethrottleRequest request = new RethrottleRequest(taskId); // tag::rethrottle-execute-async - client.reindexRethrottleAsync(rethrottleRequest, RequestOptions.DEFAULT, listener); // <1> + client.reindexRethrottleAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.updateByQueryRethrottleAsync(request, RequestOptions.DEFAULT, listener); // <2> + client.deleteByQueryRethrottleAsync(request, RequestOptions.DEFAULT, listener); // <3> // end::rethrottle-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); } diff --git a/docs/java-rest/high-level/document/reindex-rethrottle.asciidoc b/docs/java-rest/high-level/document/rethrottle.asciidoc similarity index 65% rename from docs/java-rest/high-level/document/reindex-rethrottle.asciidoc rename to docs/java-rest/high-level/document/rethrottle.asciidoc index 77b2fc335862f..9f6fd69dbcd49 100644 --- a/docs/java-rest/high-level/document/reindex-rethrottle.asciidoc +++ b/docs/java-rest/high-level/document/rethrottle.asciidoc @@ -1,15 +1,15 @@ -[[java-rest-high-document-reindex-rethrottle]] -=== Reindex Rethrottle API +[[java-rest-high-document-rethrottle]] +=== Rethrottle API -[[java-rest-high-document-reindex-rethrottle-request]] -==== Reindex Rethrolle Request +[[java-rest-high-document-rethrottle-request]] +==== Rethrottle Request -A `RethrottleRequest` can be used to change existing throttling on a runnind -reindex task or disable it entirely. It requires the task Id of the reindex -task to change. +A `RethrottleRequest` can be used to change the current throttling on a running +reindex, update-by-query or delete-by-query task or to disable throttling of +the task entirely. It requires the task Id of the task to change. In its simplest form, you can use it to disable throttling of a running -reindex task using the following: +task using the following: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- @@ -26,7 +26,19 @@ include-tagged::{doc-tests}/CRUDDocumentationIT.java[rethrottle-request] -------------------------------------------------- <1> Request to change the throttling of a task to 100 requests per second -[[java-rest-high-document-reindex-rethrottle-async]] +The rethrottling request can be executed by using one of the three appropriate +methods depending on whether a reindex, update-by-query or delete-by-query task +should be rethrottled: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/CRUDDocumentationIT.java[rethrottle-request-execution] +-------------------------------------------------- +<1> Execute reindex rethrottling request +<2> The same for update-by-query +<3> The same for delete-by-query + +[[java-rest-high-document-rethrottle-async]] ==== Asynchronous Execution The asynchronous execution of a rethrottle request requires both the `RethrottleRequest` @@ -37,8 +49,9 @@ method: -------------------------------------------------- include-tagged::{doc-tests}/CRUDDocumentationIT.java[rethrottle-execute-async] -------------------------------------------------- -<1> The RethrottleRequest to execute and the ActionListener to use when the -execution completes +<1> Execute reindex rethrottling asynchronously +<2> The same for update-by-query +<3> The same for delete-by-query The asynchronous method does not block and returns immediately. Once it is completed the `ActionListener` is called back using the `onResponse` method @@ -47,12 +60,12 @@ it failed. A typical listener looks like this: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/CRUDDocumentationIT.java[rethrottle-request-async] +include-tagged::{doc-tests}/CRUDDocumentationIT.java[rethrottle-request-async-listener] -------------------------------------------------- <1> Code executed when the request is successfully completed <2> Code executed when the request fails with an exception -[[java-rest-high-document-reindex-retrottle-response]] +[[java-rest-high-document-retrottle-response]] ==== Rethrottle Response Rethrottling returns the task that has been rethrottled in the form of a diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index f91a2ed8e7507..88e2dad13ba98 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -18,7 +18,7 @@ Multi-document APIs:: * <> * <> * <> -* <> +* <> include::document/index.asciidoc[] include::document/get.asciidoc[] @@ -30,7 +30,7 @@ include::document/multi-get.asciidoc[] include::document/reindex.asciidoc[] include::document/update-by-query.asciidoc[] include::document/delete-by-query.asciidoc[] -include::document/reindex-rethrottle.asciidoc[] +include::document/rethrottle.asciidoc[] == Search APIs diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json b/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json new file mode 100644 index 0000000000000..a2e1af5d8a701 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json @@ -0,0 +1,25 @@ +{ + "delete_by_query_rethrottle": { + "documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html", + "methods": ["POST"], + "url": { + "path": "/_delete_by_query/{task_id}/_rethrottle", + "paths": ["/_reindex/{task_id}/_rethrottle", "/_update_by_query/{task_id}/_rethrottle", "/_delete_by_query/{task_id}/_rethrottle"], + "parts": { + "task_id": { + "type": "string", + "required" : true, + "description": "The task id to rethrottle" + } + }, + "params": { + "requests_per_second": { + "type": "number", + "required": true, + "description": "The throttle to set on this request in floating sub-requests per second. -1 means set no throttle." + } + } + }, + "body": null + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json b/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json new file mode 100644 index 0000000000000..99be0d68fac0f --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json @@ -0,0 +1,25 @@ +{ + "update_by_query_rethrottle": { + "documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html", + "methods": ["POST"], + "url": { + "path": "/_update_by_query/{task_id}/_rethrottle", + "paths": ["/_reindex/{task_id}/_rethrottle", "/_update_by_query/{task_id}/_rethrottle", "/_delete_by_query/{task_id}/_rethrottle"], + "parts": { + "task_id": { + "type": "string", + "required" : true, + "description": "The task id to rethrottle" + } + }, + "params": { + "requests_per_second": { + "type": "number", + "required": true, + "description": "The throttle to set on this request in floating sub-requests per second. -1 means set no throttle." + } + } + }, + "body": null + } +} From a52a97bf4b6ebe4260c9a958438898b24cf44391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Tue, 2 Oct 2018 16:15:43 +0200 Subject: [PATCH 2/3] Drop the variant paths in rethrottle rest specs --- .../resources/rest-api-spec/api/delete_by_query_rethrottle.json | 2 +- .../main/resources/rest-api-spec/api/reindex_rethrottle.json | 2 +- .../resources/rest-api-spec/api/update_by_query_rethrottle.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json b/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json index a2e1af5d8a701..f49af01cfc3b7 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/delete_by_query_rethrottle.json @@ -4,7 +4,7 @@ "methods": ["POST"], "url": { "path": "/_delete_by_query/{task_id}/_rethrottle", - "paths": ["/_reindex/{task_id}/_rethrottle", "/_update_by_query/{task_id}/_rethrottle", "/_delete_by_query/{task_id}/_rethrottle"], + "paths": ["/_delete_by_query/{task_id}/_rethrottle"], "parts": { "task_id": { "type": "string", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/reindex_rethrottle.json b/rest-api-spec/src/main/resources/rest-api-spec/api/reindex_rethrottle.json index 4004409ab6883..2763eb8983fd5 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/reindex_rethrottle.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/reindex_rethrottle.json @@ -4,7 +4,7 @@ "methods": ["POST"], "url": { "path": "/_reindex/{task_id}/_rethrottle", - "paths": ["/_reindex/{task_id}/_rethrottle", "/_update_by_query/{task_id}/_rethrottle", "/_delete_by_query/{task_id}/_rethrottle"], + "paths": ["/_reindex/{task_id}/_rethrottle"], "parts": { "task_id": { "type": "string", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json b/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json index 99be0d68fac0f..9ec2540b43006 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/update_by_query_rethrottle.json @@ -4,7 +4,7 @@ "methods": ["POST"], "url": { "path": "/_update_by_query/{task_id}/_rethrottle", - "paths": ["/_reindex/{task_id}/_rethrottle", "/_update_by_query/{task_id}/_rethrottle", "/_delete_by_query/{task_id}/_rethrottle"], + "paths": ["/_update_by_query/{task_id}/_rethrottle"], "parts": { "task_id": { "type": "string", From dc2a1e6fd5f1944f9bb5ba489b83f6bdc8c79f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Tue, 2 Oct 2018 21:42:00 +0200 Subject: [PATCH 3/3] reindenting --- .../src/test/java/org/elasticsearch/client/CrudIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java index 73b8ebf381079..3f90552fe9b54 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java @@ -901,7 +901,7 @@ public void testDeleteByQuery() throws Exception { .add(new IndexRequest(sourceIndex, "type", "2") .source(Collections.singletonMap("foo", 2), XContentType.JSON)) .add(new IndexRequest(sourceIndex, "type", "3") - .source(Collections.singletonMap("foo", 3), XContentType.JSON)) + .source(Collections.singletonMap("foo", 3), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT ).status()