openapi: 3.2.0 info: title: Elasticsearch Tasks API description: 'Elasticsearch provides REST APIs that are used by the UI components and can be called directly to configure and access Elasticsearch features. ## Documentation source and versions This documentation is derived from the main branch of the elasticsearch-specification repository. It is provided under license Attribution-NonCommercial-NoDerivatives 4.0 International. This documentation contains work-in-progress information for future Elastic Stack releases.' license: name: Apache 2.0 url: https://github.com/elastic/elasticsearch-specification/blob/main/LICENSE version: '' security: - apiKeyAuth: [] - basicAuth: [] - bearerAuth: [] tags: - name: Tasks description: The task management APIs enable you to get information about the tasks currently running on one or more nodes in the cluster. externalDocs: description: Learn more. url: https://www.elastic.co/docs/troubleshoot/elasticsearch/task-queue-backlog x-displayName: Task management paths: /_tasks/_cancel: post: tags: - Tasks summary: Cancel a task description: 'WARNING: The task management API is new and should still be considered a beta feature. The API may change in ways that are not backwards compatible. A task may continue to run for some time after it has been cancelled because it may not be able to safely stop its current activity straight away. It is also possible that Elasticsearch must complete its work on other tasks before it can process the cancellation. The get task information API will continue to list these cancelled tasks until they complete. The cancelled flag in the response indicates that the cancellation command has been processed and the task will stop as soon as possible. To troubleshoot why a cancelled task does not complete promptly, use the get task information API with the `?detailed` parameter to identify the other tasks the system is running. You can also use the node hot threads API to obtain detailed information about the work the system is doing instead of completing the cancelled task.' operationId: tasks-cancel parameters: - in: query name: actions description: A comma-separated list or wildcard expression of actions that is used to limit the request. deprecated: false schema: oneOf: - type: string - type: array items: type: string style: form - in: query name: nodes description: A comma-separated list of node IDs or names that is used to limit the request. deprecated: false schema: type: array items: type: string style: form - in: query name: parent_task_id description: A parent task ID that is used to limit the tasks. deprecated: false schema: type: string style: form - in: query name: wait_for_completion description: If true, the request blocks until all found tasks are complete. deprecated: false schema: type: boolean style: form responses: '200': description: '' content: application/json: schema: $ref: '#/components/schemas/tasks._types.TaskListResponseBase' x-state: Technical preview; Added in 2.3.0 x-variations: - "
\n POST\n /_tasks/_cancel\n
\n " x-req-auth: - 'Cluster privileges: `manage` ' x-api: cancel.tasks x-category: info x-codeSamples: - lang: Console source: 'POST _tasks//_cancel ' - lang: Python source: "resp = client.tasks.cancel(\n task_id=\"\",\n)" - lang: JavaScript source: "const response = await client.tasks.cancel({\n task_id: \"\",\n});" - lang: Ruby source: "response = client.tasks.cancel(\n task_id: \"\"\n)" - lang: PHP source: "$resp = $client->tasks()->cancel([\n \"task_id\" => \"\",\n]);" - lang: curl source: 'curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" "$ELASTICSEARCH_URL/_tasks//_cancel"' - lang: Java source: "client.tasks().cancel(c -> c\n .taskId(\"\")\n);\n" x-metaTags: - content: Elasticsearch name: product_name /_tasks/{task_id}/_cancel: post: tags: - Tasks summary: Cancel a task description: 'WARNING: The task management API is new and should still be considered a beta feature. The API may change in ways that are not backwards compatible. A task may continue to run for some time after it has been cancelled because it may not be able to safely stop its current activity straight away. It is also possible that Elasticsearch must complete its work on other tasks before it can process the cancellation. The get task information API will continue to list these cancelled tasks until they complete. The cancelled flag in the response indicates that the cancellation command has been processed and the task will stop as soon as possible. To troubleshoot why a cancelled task does not complete promptly, use the get task information API with the `?detailed` parameter to identify the other tasks the system is running. You can also use the node hot threads API to obtain detailed information about the work the system is doing instead of completing the cancelled task.' operationId: tasks-cancel-1 parameters: - in: path name: task_id description: The task identifier. required: true deprecated: false schema: $ref: '#/components/schemas/_types.TaskId' style: simple - in: query name: actions description: A comma-separated list or wildcard expression of actions that is used to limit the request. deprecated: false schema: oneOf: - type: string - type: array items: type: string style: form - in: query name: nodes description: A comma-separated list of node IDs or names that is used to limit the request. deprecated: false schema: type: array items: type: string style: form - in: query name: parent_task_id description: A parent task ID that is used to limit the tasks. deprecated: false schema: type: string style: form - in: query name: wait_for_completion description: If true, the request blocks until all found tasks are complete. deprecated: false schema: type: boolean style: form responses: '200': description: '' content: application/json: schema: $ref: '#/components/schemas/tasks._types.TaskListResponseBase' x-state: Technical preview; Added in 2.3.0 x-variations: - "
\n POST\n /_tasks/{task_id}/_cancel\n
\n " x-req-auth: - 'Cluster privileges: `manage` ' x-api: cancel.tasks x-category: info x-codeSamples: - lang: Console source: 'POST _tasks//_cancel ' - lang: Python source: "resp = client.tasks.cancel(\n task_id=\"\",\n)" - lang: JavaScript source: "const response = await client.tasks.cancel({\n task_id: \"\",\n});" - lang: Ruby source: "response = client.tasks.cancel(\n task_id: \"\"\n)" - lang: PHP source: "$resp = $client->tasks()->cancel([\n \"task_id\" => \"\",\n]);" - lang: curl source: 'curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" "$ELASTICSEARCH_URL/_tasks//_cancel"' - lang: Java source: "client.tasks().cancel(c -> c\n .taskId(\"\")\n);\n" x-metaTags: - content: Elasticsearch name: product_name /_tasks/{task_id}: get: tags: - Tasks summary: Get task information description: 'Get information about a task currently running in the cluster. WARNING: The task management API is new and should still be considered a beta feature. The API may change in ways that are not backwards compatible. If the task identifier is not found, a 404 response code indicates that there are no resources that match the request.' operationId: tasks-get parameters: - in: path name: task_id description: The task identifier. required: true deprecated: false schema: $ref: '#/components/schemas/_types.Id' style: simple - in: query name: timeout description: 'The period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.' deprecated: false schema: $ref: '#/components/schemas/_types.Duration' style: form - in: query name: wait_for_completion description: If `true`, the request blocks until the task has completed. deprecated: false schema: type: boolean style: form responses: '200': description: '' content: application/json: schema: type: object properties: completed: type: boolean task: allOf: - $ref: '#/components/schemas/tasks._types.TaskInfo' response: type: object error: allOf: - $ref: '#/components/schemas/_types.ErrorCause' required: - completed - task examples: GetTaskResponseExample1: summary: Get cluster actions description: 'A successful response from `GET _tasks?actions=cluster:*`, which retrieves all cluster-related tasks. ' value: "{\n \"nodes\" : {\n \"oTUltX4IQMOUUVeiohTt8A\" : {\n \"name\" : \"H5dfFeA\",\n \"transport_address\" : \"127.0.0.1:9300\",\n \"host\" : \"127.0.0.1\",\n \"ip\" : \"127.0.0.1:9300\",\n \"tasks\" : {\n \"oTUltX4IQMOUUVeiohTt8A:124\" : {\n \"node\" : \"oTUltX4IQMOUUVeiohTt8A\",\n \"id\" : 124,\n \"type\" : \"direct\",\n \"action\" : \"cluster:monitor/tasks/lists[n]\",\n \"start_time_in_millis\" : 1458585884904,\n \"running_time_in_nanos\" : 47402,\n \"cancellable\" : false,\n \"parent_task_id\" : \"oTUltX4IQMOUUVeiohTt8A:123\"\n },\n \"oTUltX4IQMOUUVeiohTt8A:123\" : {\n \"node\" : \"oTUltX4IQMOUUVeiohTt8A\",\n \"id\" : 123,\n \"type\" : \"transport\",\n \"action\" : \"cluster:monitor/tasks/lists\",\n \"start_time_in_millis\" : 1458585884904,\n \"running_time_in_nanos\" : 236042,\n \"cancellable\" : false\n }\n }\n }\n }\n}" GetTaskResponseExample2: summary: Get details about a delete by query description: 'A successful response from `GET _tasks?detailed=true&actions=*/delete/byquery`, which gets the status of a delete by query operation. The `status` object contains the actual status. `total` is the total number of operations that the reindex expects to perform. You can estimate the progress by adding the `updated`, `created`, and `deleted` fields. The request will finish when their sum is equal to the `total` field. ' value: "{\n \"nodes\" : {\n \"r1A2WoRbTwKZ516z6NEs5A\" : {\n \"name\" : \"r1A2WoR\",\n \"transport_address\" : \"127.0.0.1:9300\",\n \"host\" : \"127.0.0.1\",\n \"ip\" : \"127.0.0.1:9300\",\n \"attributes\" : {\n \"testattr\" : \"test\",\n \"portsfile\" : \"true\"\n },\n \"tasks\" : {\n \"r1A2WoRbTwKZ516z6NEs5A:36619\" : {\n \"node\" : \"r1A2WoRbTwKZ516z6NEs5A\",\n \"id\" : 36619,\n \"type\" : \"transport\",\n \"action\" : \"indices:data/write/delete/byquery\",\n \"status\" : { \n \"total\" : 6154,\n \"updated\" : 0,\n \"created\" : 0,\n \"deleted\" : 3500,\n \"batches\" : 36,\n \"version_conflicts\" : 0,\n \"noops\" : 0,\n \"retries\": 0,\n \"throttled_millis\": 0\n },\n \"description\" : \"\"\n }\n }\n }\n }\n}" x-state: Technical preview; Added in 5.0.0 x-variations: - "
\n GET\n /_tasks/{task_id}\n
\n " x-req-auth: - 'Cluster privileges: `monitor` ' x-api: get.tasks x-category: info x-codeSamples: - lang: Console source: 'GET _tasks?detailed=true&actions=*/delete/byquery ' - lang: Python source: "resp = client.tasks.list(\n detailed=True,\n actions=\"*/delete/byquery\",\n)" - lang: JavaScript source: "const response = await client.tasks.list({\n detailed: \"true\",\n actions: \"*/delete/byquery\",\n});" - lang: Ruby source: "response = client.tasks.list(\n detailed: \"true\",\n actions: \"*/delete/byquery\"\n)" - lang: PHP source: "$resp = $client->tasks()->list([\n \"detailed\" => \"true\",\n \"actions\" => \"*/delete/byquery\",\n]);" - lang: curl source: 'curl -X GET -H "Authorization: ApiKey $ELASTIC_API_KEY" "$ELASTICSEARCH_URL/_tasks?detailed=true&actions=*/delete/byquery"' - lang: Java source: "client.tasks().list(l -> l\n .actions(\"*/delete/byquery\")\n .detailed(true)\n);\n" x-metaTags: - content: Elasticsearch name: product_name /_tasks: get: tags: - Tasks summary: Get all tasks description: 'Get information about the tasks currently running on one or more nodes in the cluster. WARNING: The task management API is new and should still be considered a beta feature. The API may change in ways that are not backwards compatible. **Identifying running tasks** The `X-Opaque-Id header`, when provided on the HTTP request header, is going to be returned as a header in the response as well as in the headers field for in the task information. This enables you to track certain calls or associate certain tasks with the client that started them. For example: ``` curl -i -H "X-Opaque-Id: 123456" "http://localhost:9200/_tasks?group_by=parents" ``` The API returns the following result: ``` HTTP/1.1 200 OK X-Opaque-Id: 123456 content-type: application/json; charset=UTF-8 content-length: 831 { "tasks" : { "u5lcZHqcQhu-rUoFaqDphA:45" : { "node" : "u5lcZHqcQhu-rUoFaqDphA", "id" : 45, "type" : "transport", "action" : "cluster:monitor/tasks/lists", "start_time_in_millis" : 1513823752749, "running_time_in_nanos" : 293139, "cancellable" : false, "headers" : { "X-Opaque-Id" : "123456" }, "children" : [ { "node" : "u5lcZHqcQhu-rUoFaqDphA", "id" : 46, "type" : "direct", "action" : "cluster:monitor/tasks/lists[n]", "start_time_in_millis" : 1513823752750, "running_time_in_nanos" : 92133, "cancellable" : false, "parent_task_id" : "u5lcZHqcQhu-rUoFaqDphA:45", "headers" : { "X-Opaque-Id" : "123456" } } ] } } } ``` In this example, `X-Opaque-Id: 123456` is the ID as a part of the response header. The `X-Opaque-Id` in the task `headers` is the ID for the task that was initiated by the REST request. The `X-Opaque-Id` in the children `headers` is the child task of the task that was initiated by the REST request.' operationId: tasks-list parameters: - in: query name: actions description: 'A comma-separated list or wildcard expression of actions used to limit the request. For example, you can use `cluser:*` to retrieve all cluster-related tasks.' deprecated: false schema: oneOf: - type: string - type: array items: type: string style: form - in: query name: detailed description: 'If `true`, the response includes detailed information about the running tasks. This information is useful to distinguish tasks from each other but is more costly to run.' deprecated: false schema: type: boolean style: form - in: query name: group_by description: "A key that is used to group tasks in the response.\nThe task lists can be grouped either by nodes or by parent tasks.\n\nSupported values include:\n - `nodes`: Group tasks by node ID.\n - `parents`: Group tasks by parent task ID.\n - `none`: Do not group tasks.\n\n" deprecated: false schema: $ref: '#/components/schemas/tasks._types.GroupBy' style: form - in: query name: nodes description: A comma-separated list of node IDs or names that is used to limit the returned information. deprecated: false schema: $ref: '#/components/schemas/_types.NodeIds' style: form - in: query name: parent_task_id description: 'A parent task identifier that is used to limit returned information. To return all tasks, omit this parameter or use a value of `-1`. If the parent task is not found, the API does not return a 404 response code.' deprecated: false schema: $ref: '#/components/schemas/_types.Id' style: form - in: query name: timeout description: 'The period to wait for each node to respond. If a node does not respond before its timeout expires, the response does not include its information. However, timed out nodes are included in the `node_failures` property.' deprecated: false schema: $ref: '#/components/schemas/_types.Duration' style: form - in: query name: wait_for_completion description: If `true`, the request blocks until the operation is complete. deprecated: false schema: type: boolean style: form responses: '200': description: '' content: application/json: schema: $ref: '#/components/schemas/tasks._types.TaskListResponseBase' examples: ListTasksResponseExample1: description: 'A successful response from `GET _tasks?actions=*search&detailed` The `detailed` parameter affects the `description` field, which contains human readable text that identifies the particular request that the task is performing. For example, it helps identify the search request being performed by a search task. ' value: "{\n \"nodes\" : {\n \"oTUltX4IQMOUUVeiohTt8A\" : {\n \"name\" : \"H5dfFeA\",\n \"transport_address\" : \"127.0.0.1:9300\",\n \"host\" : \"127.0.0.1\",\n \"ip\" : \"127.0.0.1:9300\",\n \"tasks\" : {\n \"oTUltX4IQMOUUVeiohTt8A:464\" : {\n \"node\" : \"oTUltX4IQMOUUVeiohTt8A\",\n \"id\" : 464,\n \"type\" : \"transport\",\n \"action\" : \"indices:data/read/search\",\n \"description\" : \"indices[test], types[test], search_type[QUERY_THEN_FETCH], source[{\\\"query\\\":...}]\",\n \"start_time_in_millis\" : 1483478610008,\n \"running_time_in_nanos\" : 13991383,\n \"cancellable\" : true,\n \"cancelled\" : false\n }\n }\n }\n }\n}" x-state: Technical preview; Added in 2.3.0 x-variations: - "
\n GET\n /_tasks\n
\n " x-req-auth: - 'Cluster privileges: `monitor` ' x-api: list.tasks x-category: info x-codeSamples: - lang: Console source: 'GET _tasks?actions=*search&detailed ' - lang: Python source: "resp = client.tasks.list(\n actions=\"*search\",\n detailed=True,\n)" - lang: JavaScript source: "const response = await client.tasks.list({\n actions: \"*search\",\n detailed: \"true\",\n});" - lang: Ruby source: "response = client.tasks.list(\n actions: \"*search\",\n detailed: \"true\"\n)" - lang: PHP source: "$resp = $client->tasks()->list([\n \"actions\" => \"*search\",\n \"detailed\" => \"true\",\n]);" - lang: curl source: 'curl -X GET -H "Authorization: ApiKey $ELASTIC_API_KEY" "$ELASTICSEARCH_URL/_tasks?actions=*search&detailed"' - lang: Java source: "client.tasks().list(l -> l\n .actions(\"*search\")\n .detailed(true)\n);\n" x-metaTags: - content: Elasticsearch name: product_name components: schemas: tasks._types.ParentTaskInfo: allOf: - $ref: '#/components/schemas/tasks._types.TaskInfo' - type: object properties: children: type: array items: $ref: '#/components/schemas/tasks._types.TaskInfo' _types.ErrorCause: description: 'Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.' type: object properties: type: description: The type of error type: string reason: description: A human-readable explanation of the error, in English. oneOf: - type: string - type: - string - 'null' stack_trace: description: The server stack trace. Present only if the `error_trace=true` parameter was sent with the request. type: string caused_by: allOf: - $ref: '#/components/schemas/_types.ErrorCause' root_cause: type: array items: $ref: '#/components/schemas/_types.ErrorCause' suppressed: type: array items: $ref: '#/components/schemas/_types.ErrorCause' required: - type _types.NodeId: type: string tasks._types.GroupBy: type: string enum: - nodes - parents - none _types.TaskFailure: type: object properties: task_id: type: number node_id: allOf: - $ref: '#/components/schemas/_types.NodeId' status: type: string reason: allOf: - $ref: '#/components/schemas/_types.ErrorCause' required: - task_id - node_id - status - reason _types.Ip: type: string _types.NodeIds: oneOf: - $ref: '#/components/schemas/_types.NodeId' - type: array items: $ref: '#/components/schemas/_types.NodeId' tasks._types.NodeTasks: type: object properties: name: allOf: - $ref: '#/components/schemas/_types.NodeId' transport_address: allOf: - $ref: '#/components/schemas/_types.TransportAddress' host: allOf: - $ref: '#/components/schemas/_types.Host' ip: allOf: - $ref: '#/components/schemas/_types.Ip' roles: type: array items: type: string attributes: type: object additionalProperties: type: string tasks: type: object additionalProperties: $ref: '#/components/schemas/tasks._types.TaskInfo' required: - tasks _types.UnitMillis: description: Time unit for milliseconds type: number tasks._types.TaskInfo: type: object properties: action: type: string cancelled: type: boolean cancellable: type: boolean description: description: 'Human readable text that identifies the particular request that the task is performing. For example, it might identify the search request being performed by a search task. Other kinds of tasks have different descriptions, like `_reindex` which has the source and the destination, or `_bulk` which just has the number of requests and the destination indices. Many requests will have only an empty description because more detailed information about the request is not easily available or particularly helpful in identifying the request.' type: string headers: type: object additionalProperties: type: string id: type: number node: allOf: - $ref: '#/components/schemas/_types.NodeId' running_time: allOf: - $ref: '#/components/schemas/_types.Duration' running_time_in_nanos: allOf: - $ref: '#/components/schemas/_types.DurationValueUnitNanos' start_time_in_millis: allOf: - $ref: '#/components/schemas/_types.EpochTimeUnitMillis' status: description: 'The internal status of the task, which varies from task to task. The format also varies. While the goal is to keep the status for a particular task consistent from version to version, this is not always possible because sometimes the implementation changes. Fields might be removed from the status for a particular request so any parsing you do of the status might break in minor releases.' type: object type: type: string parent_task_id: allOf: - $ref: '#/components/schemas/_types.TaskId' required: - action - cancellable - headers - id - node - running_time_in_nanos - start_time_in_millis - type _types.Host: type: string _types.Duration: externalDocs: url: https://www.elastic.co/docs/reference/elasticsearch/rest-apis/api-conventions#time-units description: 'A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and `d` (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.' oneOf: - type: string - type: string enum: - '-1' - type: string enum: - '0' _types.UnitNanos: description: Time unit for nanoseconds type: number _types.EpochTimeUnitMillis: allOf: - $ref: '#/components/schemas/_types.UnitMillis' tasks._types.TaskInfos: oneOf: - type: array items: $ref: '#/components/schemas/tasks._types.TaskInfo' - type: object additionalProperties: $ref: '#/components/schemas/tasks._types.ParentTaskInfo' _types.TransportAddress: type: string tasks._types.TaskListResponseBase: type: object properties: node_failures: type: array items: $ref: '#/components/schemas/_types.ErrorCause' task_failures: type: array items: $ref: '#/components/schemas/_types.TaskFailure' nodes: description: Task information grouped by node, if `group_by` was set to `node` (the default). type: object additionalProperties: $ref: '#/components/schemas/tasks._types.NodeTasks' tasks: description: 'Either a flat list of tasks if `group_by` was set to `none`, or grouped by parents if `group_by` was set to `parents`.' allOf: - $ref: '#/components/schemas/tasks._types.TaskInfos' _types.DurationValueUnitNanos: allOf: - $ref: '#/components/schemas/_types.UnitNanos' _types.TaskId: type: string _types.Id: type: string securitySchemes: apiKeyAuth: type: apiKey in: header name: Authorization description: "Elasticsearch APIs support key-based authentication.\nYou must create an API key and use the encoded value in the request header.\nFor example:\n\n```\ncurl -X GET \"${ES_URL}/_cat/indices?v=true\" \\\n -H \"Authorization: ApiKey ${API_KEY}\"\n```\n\nTo get API keys, use the `/_security/api_key` APIs." basicAuth: type: http scheme: basic bearerAuth: type: http scheme: bearer description: 'Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API. For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)' x-tagGroups: - name: AI & Machine Learning tags: - analytics - graph - inference - ml - ml anomaly - ml data frame - ml trained model - query_rules - text_structure - name: Cluster Management tags: - ccr - cluster - connector - data stream - ilm - indices - rollup - script - search_application - searchable_snapshots - slm - snapshot - name: Data Processing tags: - enrich - fleet - ingest - logstash - synonyms - transform - name: Information & Monitoring tags: - cat - features - health_report - info - license - migration - tasks - watcher - xpack - name: Search & Document APIs tags: - document - eql - esql - search - sql - name: Security tags: - security