List Tasks API

edit

The List Tasks API allows to get information about the tasks currently executing in the cluster.

List Tasks Request

edit

A ListTasksRequest:

ListTasksRequest request = new ListTasksRequest();

There is no required parameters. By default the client will list all tasks and will not wait for task completion.

Parameters

edit
request.setActions("cluster:*"); 
request.setNodes("nodeId1", "nodeId2"); 
request.setParentTaskId(new TaskId("parentTaskId", 42)); 

Request only cluster-related tasks

Request all tasks running on nodes nodeId1 and nodeId2

Request only children of a particular task

request.setDetailed(true); 

Should the information include detailed, potentially slow to generate data. Defaults to false

request.setWaitForCompletion(true); 
request.setTimeout(TimeValue.timeValueSeconds(50)); 
request.setTimeout("50s"); 

Should this request wait for all found tasks to complete. Defaults to false

Timeout for the request as a TimeValue. Applicable only if setWaitForCompletion is true. Defaults to 30 seconds

Timeout as a String

Synchronous Execution

edit
ListTasksResponse response = client.tasks().list(request, RequestOptions.DEFAULT);

Asynchronous Execution

edit

The asynchronous execution of a cluster update settings requires both the ListTasksRequest instance and an ActionListener instance to be passed to the asynchronous method:

client.tasks().listAsync(request, RequestOptions.DEFAULT, listener); 

The ListTasksRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed.

A typical listener for ListTasksResponse looks like:

ActionListener<ListTasksResponse> listener =
        new ActionListener<ListTasksResponse>() {
            @Override
            public void onResponse(ListTasksResponse response) {
                
            }

            @Override
            public void onFailure(Exception e) {
                
            }
        };

Called when the execution is successfully completed. The response is provided as an argument

Called in case of a failure. The raised exception is provided as an argument

List Tasks Response

edit
List<TaskInfo> tasks = response.getTasks(); 

List of currently running tasks

Map<String, List<TaskInfo>> perNodeTasks = response.getPerNodeTasks(); 
List<TaskGroup> groups = response.getTaskGroups(); 

List of tasks grouped by a node

List of tasks grouped by a parent task

List<ElasticsearchException> nodeFailures = response.getNodeFailures(); 
List<TaskOperationFailure> taskFailures = response.getTaskFailures(); 

List of node failures

List of tasks failures