How to monitor Reindexing progress through REST API
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
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"