use of org.opensearch.index.reindex.RethrottleRequestBuilder in project OpenSearch by opensearch-project.
the class ReindexDocumentationIT method testTasks.
public void testTasks() throws Exception {
final Client client = client();
final ReindexRequestBuilder builder = reindexAndPartiallyBlock();
{
// tag::update-by-query-list-tasks
ListTasksResponse tasksList = client.admin().cluster().prepareListTasks().setActions(UpdateByQueryAction.NAME).setDetailed(true).get();
for (TaskInfo info : tasksList.getTasks()) {
TaskId taskId = info.getTaskId();
BulkByScrollTask.Status status = (BulkByScrollTask.Status) info.getStatus();
// do stuff
}
// end::update-by-query-list-tasks
}
TaskInfo mainTask = CancelTests.findTaskToCancel(ReindexAction.NAME, builder.request().getSlices());
BulkByScrollTask.Status status = (BulkByScrollTask.Status) mainTask.getStatus();
assertNull(status.getReasonCancelled());
TaskId taskId = mainTask.getTaskId();
{
// tag::update-by-query-get-task
GetTaskResponse get = client.admin().cluster().prepareGetTask(taskId).get();
// end::update-by-query-get-task
}
{
// tag::update-by-query-cancel-task
// Cancel all update-by-query requests
client.admin().cluster().prepareCancelTasks().setActions(UpdateByQueryAction.NAME).get().getTasks();
// Cancel a specific update-by-query request
client.admin().cluster().prepareCancelTasks().setTaskId(taskId).get().getTasks();
// end::update-by-query-cancel-task
}
{
// tag::update-by-query-rethrottle
new RethrottleRequestBuilder(client, RethrottleAction.INSTANCE).setTaskId(taskId).setRequestsPerSecond(2.0f).get();
// end::update-by-query-rethrottle
}
// unblocking the blocked update
ALLOWED_OPERATIONS.release(builder.request().getSlices());
}
Aggregations