Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

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

1 vote
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
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

125 views 1 2
Read article

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