It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Run the indexing service in JIRA in an isolated thread

Deleted user May 31, 2018

Hello everyone,

We have developed a script that we use as a Reindex Service that runs every minute.

How can we run it in an isolated thread, so Jira does not go down, in case of any problem with reindexing. Can you help me, please?

Thanks in advance.
Regards,

Almu

 

 

2 answers

2 accepted

@[deleted]In my opinion it is not  a  good idea to  run indexing every minute, why  because in case you have a large JIRA  instance , this will  drastically  reduce JIRA performance. my advice to you is to perform indexing like once  a day in your  production ( lets say  at  night when less user are accessing Jira)

Even better run a background indexing  see  REST API documentation https://confluence.atlassian.com/jirakb/how-to-trigger-re-indexing-using-rest-request-via-curl-command-663617587.html, you  can add  it in your  script in the case where you use linux/unixlike server and use cron tab in linux/Unixlike servers to  define when  reindexing should be triggered automatically.

 

Best!

Deleted user May 31, 2018

Hi Moses Thomas,

I have inherited this Jira Server, and someone created a groovy script that runs as a Service in Jira. Look:

Reindex Service com.onresolve.jira.groovy.GroovyService

input-file: /mnt/nas/jira/ReindexService.groovy

Schedule 0 0/1 * 1/1 * ? *

I am not sure whether the best option is to delete this service or schedule it in this way

0 59 23 * * *

What is your opinion, please?

Thx & BR,

ALmu

@[deleted] I will  suggest  you  schedule is daily.

Deleted user Jun 04, 2018

Thanks

Hi @[deleted],

 

Will it be possible for you to share the groovy script with me? We have a similar need to write a re-index service that we plan to run every week. I will be much obliged. 

 

Thanks,

Rajat 

Deleted user Oct 22, 2018

Hi Rajat

Here you are

cat ReindexService.groovy


def usuario = "adminuser"
def filter_id = "10327"

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.search.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IndexException
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Category
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.util.ImportUtils
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.ComponentManager

import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.index.*;

WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );

 
String jqlSearch = " filter="+ filter_id;
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
ComponentManager componentManager = ComponentManager.getInstance()
CommentManager commentManager = ComponentAccessor.getCommentManager()
IssueManager issueManager = ComponentAccessor.getIssueManager();
UserUtil userUtil = ComponentAccessor.getUserUtil()
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def userManager = ComponentAccessor.getUserManager()
def user2 = userManager.getUserByName(usuario)


Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "START Reindex filter Service"

def String adminUserName = usuario
def String nagComment = ""

SearchService.ParseResult parseResult = searchService.parseQuery(user2, jqlSearch)

if (parseResult.isValid()) {
def searchResult = searchService.search(user2, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
log.debug "Entro... size:" + issues.size();

for ( issue in issues ){

def issueobtained = issueManager.getIssueObject(issue.getKey());
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issueIndexingService.reIndex(issueobtained);

}
log.debug "FINISH Reindex filter Service"

} else {
log.debug("Invalid JQL: " + jqlSearch);
}

 

Cheers,

Almu

1 vote
Answer accepted

Ok, while the principle of "index in another thread" is a good abstract idea, your question scares me.

Why are you doing this?

Indexing is not something you should ever have to think about in Jira.  Questions starting with "I want to index" are almost always posted by people who are trying to do really bad things in Jira (inadvertently, as they don't understand the internals, and are trying to do something in a way they haven't realised is totally wrong)

Deleted user May 31, 2018

Hi Nic,

I have inherited this Jira Server, and someone created a groovy script that runs as a Service in Jira, every minute. I do not know why this was done. In your opinion, do I have to delete this service because Jira does reindexing automatically when needed?

Thx & BR,

Almu

Before you delete it, you really should find out why they did this. 

My best guess is they were hiding a massive problem that they've created elsewhere.

You may only be able to identify that by stopping it running, and seeing what goes wrong!

But in the long run, yes, absolutely, you need rid of this completely, it's a very poor practice and totally unneccessary.

Hi @Moses Thomas and @Nic Brough {Adaptavist} 

I would like to use this API call specified on this doc to re-index jira server through linux terminal.

https://confluence.atlassian.com/jirakb/reindex-jira-server-using-rest-api-via-curl-command-663617587.html?_ga=2.225356698.1460643556.1572270390-554649307.1572270390

Just one question, i am getting "authentication failure" when i try and get this working. I just use root without any password, so how would i run this?

curl -u root:password -X POST $JIRAURL/rest/api/2/reindex?type=FOREGROUND

Kind regards,

--Bibin

bibin.koshy@cmrsurgical.com  You cannot not use linux user to authenticate  login  to  Jira, user must  be admin user in  Jira.  use a  dedicated user with  admin  rights  in Jira.

 

Best regards,

Mo

Is "root" a valid admin user in Jira?

(Standard advice here though - do NOT do this automatically, you should not need to do it)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

273 views 1 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you