Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Incorrect usage of JIRA/lucene search API

Hi Everybody!

In our Jira 8.3.2. we have a lot of calculated fields that, based on an issue field, perform a JQL on the rest of the projects and gather a list of issues. From that list of issues we then get some custom field values and calculate them in order to get a total value (for ex. total estimated effort for a project). The scripts are written and running using Scriptrunner v6.6.0.

Lately, we've noticed some errors in the logs when the fields are calculated:

2020-10-10 10:13:47,174 g2gcrm-69914:Cron Service ERROR anonymous [c.o.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: XXXX-2127, field: Custom Field21 java.lang.IllegalStateException: Incorrect usage of JIRA/lucene search API. You can only create/use: ManagedIndexSearcher inside a context (request or Jira-Thread-Local). Check: JiraThreadLocalUtils for details.

The errors don’t appear on one of our staging environments but are present on the live instance which I assume is because the live environment is much busier and there are a lot of queries in the Lucene index.
I did some research and on the JiraThreadLocalUtil class, but unfortunately there is not much documentation to rely on.
The bit of code that I assume generates this error looks like: searchResults = null;
try {
    searchResults =, query, pagerFilter);
} catch (SearchException e) {
    return (Double) 0 ;

I saw one idea on a post about using “ThreadLocalUtil” in the loop, transforming to:

try {
try {
searchResults =, query, pagerFilter);
} catch (SearchException e) {
return (Double) 0 ;
} finally
jiraThreadLocalUtil.postCall(log, null)

However, this approach seems to break other things in Jira. I noticed some strange behavior when running filters that include the scripted fields: page formatting is off, results are not showing, "Activity" stream section is not showing, etc. 

Has anybody noticed this behavior and have any ideas on how to overcome this?


2 answers

1 accepted

5 votes
Answer accepted

I'm going to post the answer here, as with the help of Adaptavist support I resolved the issue by refactoring the code to:

try {


     searchResults =, query, pagerFilter);

} catch (SearchException e) {


    return (Double) total;

} finally {


by using methods from a different class:

import com.atlassian.jira.issue.index.ThreadLocalSearcherCache

although the documentation for this class states:

Low level lucene searcher context. You almost never want to use this. Most of the time you want: JiraThreadLocalUtils.wrap(Runnable) or JiraThreadLocalUtils.wrap(java.util.concurrent.Callable)

Thank you for this


I'm still curious as to why this happens. I have encountered the same behavior.

Shouldn't each instance of a scripted field, that exists in an issue, have a context i.e. project + issuetype?

Or is there something I'm not understanding correctly.

Would really appreciate it if somebody could shed some light on this whole thing, like what is the problem or why there is no context, when there should be one.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events