Elastic Search

Elasticsearch Task Management

“In this post, we will look at one of the Elasticsearch experimental API (at the time of writing this guide) that enables us to view information about the currently running tasks in a cluster.

Task management is a huge factor for any administrator, and when working with a complex system such as Elasticsearch, you will need to do some task monitoring.”

Let us cover what this API entails and how it can help you as a sys admin.

NOTE: Depending on your cluster configuration and security settings, this API may require monitor privileges.

Request Syntax

The following shows the syntax for sending the request to the task management API.

GET /_tasks/<task_id>

GET /_tasks

Once you request the API, the command should return detailed information about the current tasks or the task with the specified ID.

Request Path Parameters

The request supports one path parameter:

  • <task_id> – a unique ID value for the task whose information you wish to retrieve. The task ID follows the pattern node_id:task_number.

Request Query Parameters

To customize the behavior and the return format of the query, you can specify the following parameters:

  1. Actions – this defines a set of actions used to limit the request. Here, you can define the actions as a list of comma-separated values.
  2. Detailed – this is a Boolean parameter that defines whether the request shows detailed information about shard recoveries or not. This option defaults to false
  3. Group_by – sets the keys used to group the tasks from the response. Accepted values include:
    • Nodes – node ID.
    • Parents – parent ID.
    • Node – do not group.
  4. Node_id – defines the node or a list of nodes from which to fetch the information.
  5. parent_task_id – defines the parent ID used to filter the response information. To show all tasks, specify the parent_task_id as -1.
  6. master_timeout – specifies the duration at which the request waits for a connection to the master node. If the request does not receive a response from the master after the master_timeout duration is elapsed, it fails and returns an error. The default duration is set to 30 sec.
  7. Timeout – similar to master_timeout, but this value defines the duration on which to wait for any response.
  8. Wait_for_completion – if true, the request is blocked until the operation exits. Defaults to false.

Response

If successful, the request will return detailed information about the specified task or tasks. If the task is not found, the request returns a 404-status code.

Example Usage

The following example shows how to use the task management API to show information about all the tasks running in the cluster (all nodes).

curl -XGET "http://localhost:9200/_tasks" -H "kbn-xsrf: reporting"

The request should provide information about the tasks in the cluster, as shown in the output below:

Example 2

In the next example, we use the nodes parameter to limit the response to only the tasks that are running in the node slave_1

curl -XGET "http://localhost:9200/_tasks?nodes=slave_1" -H "kbn-xsrf: reporting"

This should return the tasks in the specified node as shown in the output below:

"tasks": {
"Fit416fGR1GJefJxOxLurw:1651265": {
"node": "slave_1",
"id": 1651265,
"type": "transport",
"action": "indices:monitor/fleet/global_checkpoints",
"start_time_in_millis": 1664214054489,
"running_time_in_nanos": 94450056094,
"cancellable": false,
"headers": {
"X-elastic-product-origin": "fleet"
          }
        }

Example 3

In example 3, we use the task management API to show information about the task with the specified ID:

curl -XGET "http://localhost:9200/_tasks/Fit416fGR1GJefJxOxLurw:1656310" -H "kbn-xsrf: reporting"

Output task information is as shown:

Example 4

To show detailed information about the task, add the detailed parameter to the request as shown:
[cc lang=”apache” width=”100%” height=”100%” escaped=”true” theme=”blackboard” nowrap=”0″]
curl -XGET “http://localhost:9200/_tasks?detailed=true” -H “kbn-xsrf: reporting”
[/c]c
This should provide additional information about the tasks:

Conclusion

This post explored how to use the task management API in Elasticsearch. This API allows us to retrieve information about currently executing tasks in the cluster.

Cheers!! & I will catch you in the next one.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list