Back to Elasticsearch

Find long-running {{esql}} queries [esql-task-management]

docs/reference/query-languages/esql/esql-task-management.md

9.5.01.7 KB
Original Source

Find long-running {{esql}} queries [esql-task-management]

You can list running {{esql}} queries with the task management APIs:

$$$esql-task-management-get-all$$$

console
GET /_tasks?pretty&detailed&group_by=parents&human&actions=*data/read/esql

Which returns a list of statuses like this:

js
{
  "node" : "2j8UKw1bRO283PMwDugNNg",
  "id" : 5326,
  "type" : "transport",
  "action" : "indices:data/read/esql",
  "description" : "FROM test | STATS MAX(d) by a, b",  <1>
  "start_time" : "2023-07-31T15:46:32.328Z",
  "start_time_in_millis" : 1690818392328,
  "running_time" : "41.7ms",                           <2>
  "running_time_in_nanos" : 41770830,
  "cancellable" : true,
  "cancelled" : false,
  "headers" : { }
}

% NOTCONSOLE

  1. The user submitted query.
  2. Time the query has been running.

You can use this to find long running queries and, if you need to, cancel them with the task cancellation API:

$$$esql-task-management-cancelEsqlQueryRequestTests$$$

console
POST _tasks/2j8UKw1bRO283PMwDugNNg:5326/_cancel

It may take a few seconds for the query to be stopped.

If you regularly find long-running {{esql}} queries, refer to Optimize {{esql}} query performance for ways to reduce scanned data, returned data, and expensive operations.

::::{tip} If you prefer a visual interface, you can use the Query activity page in {{kib}} to view and manage all running queries — including ES|QL — directly from the UI. ::::