Tasks
A task is any operation you run in a cluster. For example, searching your data collection of books for a title or author name is a task. When you run OpenSearch, a task is automatically created to monitor your cluster’s health and performance. For more information about all of the tasks currently executing in your cluster, you can use the API operation.
The following request returns information about all of your tasks:
copy
By including a task ID, you can get information specific to a particular task. Note that a task ID consists of a node’s identifying string and the task’s numerical ID. For example, if your node’s identifying string is nodestring
and the task’s numerical ID is 1234
, then your task ID is nodestring:1234
. You can find this information by running the tasks
operation:
GET _tasks/<task_id>
copy
Note that if a task finishes running, it won’t be returned as part of your request. For an example of a task that takes a little longer to finish, you can run the _reindex API operation on a larger document, and then run tasks
.
Sample Response
{
"nodes": {
"Mgqdm0r9SEGClWxp_RbnaQ": {
"name": "opensearch-node1",
"transport_address": "172.18.0.3:9300",
"host": "172.18.0.3",
"ip": "172.18.0.3:9300",
"roles": [
"data",
"ingest",
"master",
"remote_cluster_client"
],
"tasks": {
"Mgqdm0r9SEGClWxp_RbnaQ:17416": {
"node": "Mgqdm0r9SEGClWxp_RbnaQ",
"id": 17416,
"type": "transport",
"action": "cluster:monitor/tasks/lists",
"start_time_in_millis": 1613599752458,
"running_time_in_nanos": 994000,
"cancellable": false,
"headers": {}
}
},
"Mgqdm0r9SEGClWxp_RbnaQ:17413": {
"node": "Mgqdm0r9SEGClWxp_RbnaQ",
"id": 17413,
"type": "transport",
"action": "indices:data/write/bulk",
"start_time_in_millis": 1613599752286,
"running_time_in_nanos": 172846500,
"cancellable": false,
"parent_task_id": "Mgqdm0r9SEGClWxp_RbnaQ:17366",
"headers": {}
},
"Mgqdm0r9SEGClWxp_RbnaQ:17366": {
"node": "Mgqdm0r9SEGClWxp_RbnaQ",
"id": 17366,
"type": "transport",
"action": "indices:data/write/reindex",
"start_time_in_millis": 1613599750929,
"running_time_in_nanos": 1529733100,
"cancellable": true,
"headers": {}
}
}
}
You can also use the following parameters with your query.
For example, this request returns tasks currently running on a node named opensearch-node1
:
GET /_tasks?nodes=opensearch-node1
copy
Sample Response
The following request returns detailed information about active search tasks:
Sample Request
curl -XGET "localhost:9200/_tasks?actions=*search&detailed
copy
Sample Response
{
"nodes" : {
"CRqNwnEeRXOjeTSYYktw-A" : {
"name" : "runTask-0",
"transport_address" : "127.0.0.1:9300",
"host" : "127.0.0.1",
"ip" : "127.0.0.1:9300",
"roles" : [
"cluster_manager",
"data",
"ingest",
"remote_cluster_client"
],
"attributes" : {
"testattr" : "test",
"shard_indexing_pressure_enabled" : "true"
},
"tasks" : {
"CRqNwnEeRXOjeTSYYktw-A:677" : {
"node" : "CRqNwnEeRXOjeTSYYktw-A",
"id" : 677,
"type" : "transport",
"action" : "indices:data/read/search",
"description" : "indices[], search_type[QUERY_THEN_FETCH], source[{\"query\":{\"query_string\":<QUERY_STRING>}}]",
"start_time_in_millis" : 1660106254525,
"running_time_in_nanos" : 1354236,
"cancellable" : true,
"cancelled" : false,
"headers" : { },
"resource_stats" : {
"total" : {
"cpu_time_in_nanos" : 0,
"memory_in_bytes" : 0
}
}
}
}
}
}
}
After getting a list of tasks, you can cancel all cancelable tasks with the following request:
POST _tasks/_cancel
copy
Note that not all tasks are cancelable. To see if a task is cancelable, refer to the cancellable
field in the response to your tasks
API request.
copy
The operation supports the same parameters as the tasks
operation. The following example shows how to cancel all cancelable tasks on multiple nodes.
POST _tasks/_cancel?nodes=opensearch-node1,opensearch-node2
copy
Attaching headers to tasks
To associate requests with tasks for better tracking, you can provide a X-Opaque-Id:<ID_number>
header as part of the HTTPS request reader of your curl
command. The API will attach the specified header in the returned result.
Usage:
copy
The _tasks
operation returns the following result.
HTTP/1.1 200 OK
X-Opaque-Id: 111111
content-type: application/json; charset=UTF-8
content-length: 768
{
"nodes": {
"Mgqdm0r9SEGClWxp_RbnaQ": {
"name": "opensearch-node1",
"transport_address": "172.18.0.4:9300",
"host": "172.18.0.4",
"ip": "172.18.0.4:9300",
"roles": [
"data",
"ingest",
"master",
"remote_cluster_client"
],
"tasks": {
"Mgqdm0r9SEGClWxp_RbnaQ:30072": {
"node": "Mgqdm0r9SEGClWxp_RbnaQ",
"id": 30072,
"type": "direct",
"action": "cluster:monitor/tasks/lists[n]",
"start_time_in_millis": 1613166701725,
"running_time_in_nanos": 245400,
"cancellable": false,
"parent_task_id": "Mgqdm0r9SEGClWxp_RbnaQ:30071",
"headers": {
"X-Opaque-Id": "111111"
}
},
"Mgqdm0r9SEGClWxp_RbnaQ:30071": {
"node": "Mgqdm0r9SEGClWxp_RbnaQ",
"id": 30071,
"type": "transport",
"action": "cluster:monitor/tasks/lists",
"start_time_in_millis": 1613166701725,
"running_time_in_nanos": 658200,
"cancellable": false,
"headers": {
"X-Opaque-Id": "111111"
}
}
}
}
}
}
This operation supports the same parameters as the tasks
operation. The following example shows how you can associate with specific tasks:
copy