Automatic jira reindex

Mihai Schwarz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2016

Hey  guys,

It is possible to schedule a JIRA reindex or write a script to do this?

Thanks!

1 answer

1 accepted

1 vote
Answer accepted
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2016

Mihai,

First of all perform reindex only when you have to. There is no need to do it regularly.

You can trigger reindex from REST API: https://docs.atlassian.com/jira/REST/server/#api/2/reindex-reindex

-Ravi

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 25, 2016

It's always worth questioning why you want to do this.  There are some cases where it makes sense, but if you're doing it because your index is regularly going wrong, then this is absolutely the wrong thing to do. 

There's a phrase "plastering over the cracks" - when your house is structurally unsound, cracks appear in the plaster as it gradually falls apart.  If you "plaster over the cracks", your house might look ok to the eye, but you're hiding the fact that it's going to fall down soon.

So, if you're doing this because you're getting indexing errors a lot, you need to fix that, not pretend you don't have a massive problem.

Like Richard Cross likes this
Mihai Schwarz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 29, 2016

@Ravi Sagar [Author - Mastering JIRA 7] Thanks for the answer!

@Nic Brough [Adaptavist] Yes, I agree with you, but I need to reindex after working hours because I make a lot of change during the day (fields, addons, etc) and I don't wanna manual reindex every time.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 29, 2016

Ok, but that's just a case of clicking it when you know you've finished your changes, exactly as Ravi said.  The REST call does that

You do not need or want to do it regularly.

 

Brad Taplin October 13, 2018

We are undoubtedly in a position of having to do this weekly, and for performance and other organizational reasons it has to be hard reindexing each Saturday night at midnight. We are pushing our little VM to the limit and I lack the cash and authority to move to dedicated hardware at this time so...

I would rather not have to logon every Saturday night to start this hard reindex. We do have ScriptRunner if that helps, and I can schedule cron jobs.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2018

Why?  Are you really re-configuring your fields every week?

Brad Taplin October 14, 2018

Because at least some of our over a thousand project admins need changes.

Our little group supports them, they in turn support over 600 teams. In any given week there will be at least a few tweaks that are not easily isolated to the project, notwithstanding scope control of custom fields in the default field contexts.

Anyhow, I found a crude approach, though would rather handle authentication otherwise. With this I may have to regularly change the password for some admin account, cron it up late each week. The account under which JIRA runs is pretty restricted, but storing plaintext passwords is not a good thing - I have the same concern re dbconfig.cfg, by the way. Here's what I tested last night in nonprod:

curl -u [acct]:[password-of-week] -X POST https://[JIRA instance]/rest/api/2/reindex?type=FOREGROUND

We may find a better way, using centrally-controlled automation, but this works. From https://confluence.atlassian.com/jirakb/how-to-trigger-re-indexing-using-rest-request-via-curl-command-663617587.html.

Like Caleb Caleb likes this
Brad Taplin May 29, 2019

Hi Caleb. FYI this also works for content reindexing in Confluence, with slightly different syntax. To do that nightly at 3 am put the following into a script, to run as the account that runs Confluence, with 750 perms (for security), and then call it via crontab.

#!/bin/bash
# This script can force content reindexing nightly.
# Call this via the service account's crontab:
# 00 03 * * * [path]/[script].sh > /dev/null 2>&1
export JAVA_HOME=[where is your Java]
export PATH=$PATH:$JAVA_HOME/bin
curl -u [acct]:[password] -X POST -H "X-Atlassian-Token: no-check" https://[Confluence instance]/rest/prototype/1/index/reindex

Got that from https://jira.atlassian.com/browse/CONFSERVER-44340.

Whoever has root on the box - assuming you run Confluence atop Linux - may first have to empower the service account to control its own crontab, lest they get roped into helping whenever this needs a tweak.

I really wish there were a way to do this that did not require storing a password in cleartext, but am not yet aware of a way to hash or otherwise obfuscate or encrypt. We do prevent users and most others from getting to that service account, but anyhow who sees the unredacted file has keys to the kingdom, so at the least great care is required regarding this script.

Oumaima KADDOURAN MEFTAH March 13, 2023

Hello @Brad Taplin

We are in a similar case, and after checking all atlassian recommendations, I got the conclusion that only there is this curl command. But I have a concern on having this password visible in the curl command. Have you found another way to scheduled re indexing? 

Thanks and regards, 

Oumaima. 

Brad Taplin March 13, 2023

Hello Oumaima,

That is a fair concern. From my years of working as a Jira admin I do not recall a better way, but for the past year I have been in another role and not working with Jira beyond membership in a Kanban team, so I do not know of any changes since.

Brad

Suggest an answer

Log in or Sign up to answer