Task Management

Solr offers a task management framework that allows users to monitor (and even cancel) certain types of long-running tasks. Queries are the only type of "task" currently supported, but additional types may be added in the future.

Registering Tasks for Task Management

Task tracking and management is an opt-in feature: tracking must be explicitly enabled on each individual task. For queries (the only type of "task" currently supported), this is done by specifying the canCancel boolean flag as a query parameter. A value of true enables task management; false (the default) leaves it disabled.

Solr will assign each task an ID for tracking purposes. Users may override this, if desired, with an arbitrary string of their choice, using the queryUUID query parameter when submitting the original query. (Users are responsible for ensuring that any queryUUID values they provide are unique and don’t conflict with other running tasks.) This ID, whether generated or provided by the user, can then be used to track or cancel the task: as a query parameter with the V1 API, or as part of the URL path with the V2 API. See the sections below for the specifics of each operation.

Task Management Operations

The task management interface supports the following types of operations:

  1. List all currently running cancellable tasks.

  2. Cancel a specific task.

  3. Query the status of a specific task.

Listing All Active Cancellable Tasks

To list all the active cancellable tasks currently running, please use the following syntax:

  • V1 API

  • V2 API

curl -X GET "http://localhost:8983/solr/collectionName/tasks/list"
curl -X GET "http://localhost:8983/v2/collections/collectionName/tasks"

Sample Response

The V1 and V2 APIs currently return taskList in different shapes.

  • V1 API

  • V2 API

{
  "responseHeader":{
    "status":0,
    "QTime":16},
  "taskList":[
    "0","q=weight_i:[0+TO+200]&canCancel=true&queryUUID=0",
    "5","q=weight_i:[0+TO+200]&canCancel=true&queryUUID=5",
    "4bcd27bb-0792-4512-a699-532fa7878bd3","q=weight_i:[0+TO+200]&canCancel=true"]}
{
  "responseHeader":{
    "status":0,
    "QTime":16},
  "tasks":[
    {
      "id":"0",
      "query":"q=weight_i:[0+TO+200]&canCancel=true&queryUUID=0"},
    {
      "id":"5",
      "query":"q=weight_i:[0+TO+200]&canCancel=true&queryUUID=5"},
    {
      "id":"4bcd27bb-0792-4512-a699-532fa7878bd3",
      "query":"q=weight_i:[0+TO+200]&canCancel=true"}]}

Cancelling an Active Cancellable Task

To cancel an active task, please use the following syntax:

  • V1 API

  • V2 API

curl -X GET "http://localhost:8983/solr/collectionName/tasks/cancel?queryUUID=5"
curl -X DELETE "http://localhost:8983/v2/collections/collectionName/tasks/5"

Sample Response

The V1 and V2 APIs currently return the cancellation result in different shapes.

If the task was found and successfully cancelled:

  • V1 API

  • V2 API

{
  "responseHeader":{
    "status":0,
    "QTime":26},
  "status":"Query with queryID 5 cancelled successfully",
  "responseCode":200}
{
  "responseHeader":{
    "status":0,
    "QTime":26},
  "status":"SUCCESS"}

If the task was not found:

With the V1 API, a task that isn’t found is still a 200 response, with responseCode in the body indicating the failure. With the V2 API, a task that isn’t found returns an actual HTTP 404, with the standard v2 error envelope.

  • V1 API

  • V2 API

{
  "responseHeader":{
    "status":0,
    "QTime":24},
  "status":"Query with queryID 5 not found",
  "responseCode":404}
{
  "responseHeader":{
    "status":404,
    "QTime":24},
  "error":{
    "metadata":{
      "error-class":"org.apache.solr.common.SolrException",
      "root-error-class":"org.apache.solr.common.SolrException"},
    "code":404,
    "msg":"NOT_FOUND"}}

Check Status of a Specific Task

To check the status of a specific task, please use the following syntax:

  • V1 API

  • V2 API

curl -X GET "http://localhost:8983/solr/collectionName/tasks/list?taskUUID=5"
curl -X GET "http://localhost:8983/v2/collections/collectionName/tasks/5"

taskUUID Parameter

With the V1 API, the taskUUID request parameter specifies which task’s status to check. With the V2 API, the task ID is instead supplied as part of the path, e.g. /v2/collections/collectionName/tasks/{taskID}.

Sample Response

The V1 and V2 APIs currently return taskStatus in different shapes.

  • V1 API

  • V2 API

{
  "responseHeader":{
    "status":0,
    "QTime":16},
  "taskStatus":"id: 5, status: active"}
{
  "responseHeader":{
    "status":0,
    "QTime":16},
  "status":"ACTIVE"}