Search in sources :

Example 1 with RethrottleRequest

use of org.opensearch.client.RethrottleRequest in project OpenSearch by opensearch-project.

the class CRUDDocumentationIT method testReindexRethrottle.

@SuppressWarnings("unused")
public void testReindexRethrottle() throws Exception {
    RestHighLevelClient client = highLevelClient();
    TaskId taskId = new TaskId("oTUltX4IQMOUUVeiohTt8A:124");
    {
        // tag::rethrottle-disable-request
        // <1>
        RethrottleRequest request = new RethrottleRequest(taskId);
    // end::rethrottle-disable-request
    }
    {
        // tag::rethrottle-request
        // <1>
        RethrottleRequest request = new RethrottleRequest(taskId, 100.0f);
    // end::rethrottle-request
    }
    {
        RethrottleRequest request = new RethrottleRequest(taskId);
        // tag::rethrottle-request-execution
        // <1>
        client.reindexRethrottle(request, RequestOptions.DEFAULT);
        // <2>
        client.updateByQueryRethrottle(request, RequestOptions.DEFAULT);
        // <3>
        client.deleteByQueryRethrottle(request, RequestOptions.DEFAULT);
    // end::rethrottle-request-execution
    }
    ActionListener<ListTasksResponse> listener;
    // tag::rethrottle-request-async-listener
    listener = new ActionListener<ListTasksResponse>() {

        @Override
        public void onResponse(ListTasksResponse response) {
        // <1>
        }

        @Override
        public void onFailure(Exception e) {
        // <2>
        }
    };
    // end::rethrottle-request-async-listener
    // Replace the empty listener by a blocking listener in test
    final CountDownLatch latch = new CountDownLatch(3);
    listener = new LatchedActionListener<>(listener, latch);
    RethrottleRequest request = new RethrottleRequest(taskId);
    // tag::rethrottle-execute-async
    client.reindexRethrottleAsync(request, RequestOptions.DEFAULT, // <1>
    listener);
    client.updateByQueryRethrottleAsync(request, RequestOptions.DEFAULT, // <2>
    listener);
    client.deleteByQueryRethrottleAsync(request, RequestOptions.DEFAULT, // <3>
    listener);
    // end::rethrottle-execute-async
    assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Also used : RethrottleRequest(org.opensearch.client.RethrottleRequest) TaskId(org.opensearch.tasks.TaskId) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse) CountDownLatch(java.util.concurrent.CountDownLatch) OpenSearchException(org.opensearch.OpenSearchException)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 OpenSearchException (org.opensearch.OpenSearchException)1 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 RethrottleRequest (org.opensearch.client.RethrottleRequest)1 TaskId (org.opensearch.tasks.TaskId)1