How to monitor Reindexing progress through REST API

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Using the REST API can be helpful in automating certain operations within Confluence.

For instance, a Confluence administrator may need to schedule a reindex and monitor its progress.  However, going through the User Interface (UI) could be rather impractical depending the time and needs.

This document provides a step-by-step procedure on how to use the Confluence REST API to trigger a site reindex and how to monitor it.

The suggested solution is provided as a set of bash commands using curl and jq to run the REST API call and manipulate json output.

You may use this example to create an automation tool on your preferred coding language.

This document is provided as-is, what means that Atlassian Support won't provide assistance on modifying this example to fit your use case.
However, we will definitely support you if a REST API call isn't working as it should.
See Atlassian Support Offerings for additional information.

Solution

We are using personal access tokens for better security. For information on how to create personal access tokens, refer to our documentation, Using Personal Access Tokens.

Triggering a new full site reindex.

To trigger a new full site reindex, you can use the REST API below:

curl -H "Authorization: Bearer <token>" --request POST "<Instance URL>/rest/prototype/latest/index/reindex" --header "Content-Type: application/json" --data "" 

This should trigger a new full-site content reindex.

Monitoring the reindex progress.

Confluence breaks data from the database to be reindexed in 3 phases, 

  • CONTENT_ONLY - Every content except attachment and user data.
  • ATTACHMENT_ONLY - Attachment data
  • USER_ONLY - User related data.

Every phase has its own progress level, which you can check in the logs or by using the call /json/reindextaskprogress.action 

To monitor index phase - /json/reindextaskprogress.action 
  • Environment variables we need be aware of prior to executing the curl command.
USER_NAME=<username> ### You must be Confluence Administrator
USER_PASSWORD=<user password>
CONFLUENCE_BASEURL=<Confluence Base URL> ### FQDN and context path without the trailing slash
  • Now run the curl command like the example below after replacing username, password and the Confluence Base URL
curl -u <username>:<password> -X GET "http://localhost:8090/json/reindextaskprogress.action" | python -mjson.tool
  • You will ideally see an output like this
{
    "compactElapsedTime": "12:12:17",
    "count": "3020121",
    "percentageComplete": "67",
    "total": "2051956"
}

Here the compactElapsedTime represents the time since the re-indexing has started. Count represents the number items to be indexed. PercentageComplete denotes the progress made so far since. the re-indexing has been kicked off. Finally, total represents the number of items those are indexed already.

The UI displays the total progress of all three phases combined, that said, to get this result using rest API we can use the following:

curl -H "Authorization: Bearer <token>" -X GET "https://<instance url>/rest/rebuildindex/latest/job"

 You will ideally see an output like this:

{
    "id": "f312058e-4730-4ba6-b793-6aa98019023b",
    "startTime": 1717686329,
    "duration": 385,
    "stage": "REBUILDING",
    "acknowledged": false,
    "progress": 18,
    "nodes": [
        {
            "nodeId": "da0e1b05",
            "state": "REBUILDING",
            "progress": 0
        }
    ],
    "createdBy": "admin",
    "type": "SITE"
} 

We can use it together with the "jq" to filter it out and get only the progress number:

curl -H "Authorization: Bearer <token>" -X GET "https://<instance url>/rest/rebuildindex/latest/job" |jq -r ".progress"



Last modified on Jun 24, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.