SearchService.search() returns unexpected results

Hello,

For some of our clients the call to SearchService.search() returns unexpected results. The issue was reported on Jira 9.
For instance, in one case it would return issues with status ‘closed’ even though the jql used in the search was specifying “status != Closed”:

Example of jql:

jql=( (project = YYY AND sprint in openSprints() and issuetype = Sub-task and labels = YYY and status != Closed) )

and the status of some the issues returned by that query:

IssueConstantImpl[[GenericEntity:Status][sequence,518][statuscategory,3][name,Closed][iconurl,/images/icons/final_closed.gif][description,The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.][id,6]]

This does not happen all the time and could not detect a pattern that could explain the issue.

NOTES:

  • The same issue happens if the jql query is saved and the filter id used as jql (jql=filer=id)
  • However, this never happens if we use the REST api /rest/api/2/search?jql=

I was hoping someone could notice anything wrong with the code we are using (which looks something like this):

private final JiraThreadLocalUtilImpl jiraThreadLocalUtil = new JiraThreadLocalUtilImpl();
private final SearchService searchService = ComponentManager.getInstance().getComponent(SearchService.class);

void search(ApplicationUser user, String jql) {


	jiraThreadLocalUtil.preCall();
	
	
	final SearchService.ParseResult parseResult = this.searchService.parseQuery(user, jql);
	
	final SearchResults<Issue> searchResults = this.searchService.search(user, parseResult.getQuery(),  new PagerFilter(0, PagerFilter.getUnlimitedFilter()));
	
	
	for (Issue issue : searchResults.getResults()) {
	
		...
	}
	
	
	jiraThreadLocalUtil.postCall(log);

}

Could be that someone has created a custom field with the same name as a system field? E.g. status

Hi @MattDoar

I was sure you could not add a custom field with that name … but it turns out, you can.
However, you cannot use the name of the custom fields in jql queries. One has to use the cf[id] format.
In addition, the fact that is consistently failing with the SearchService and consistently working through the rest api makes me think is something wrong with the code (some additional setup missing).

Interesting, I didn’t know that JQL checks for that. Which is good

Yeah, the fact it works with REST is pretty odd. I was wondering about a broken Lucene index but then it wouldn’t work in REST. I think the next approach is to make the query simpler one clause at a time to see when the expected issues appear. Or find an issue ABC-123 and add it to the query with
a clause “and key = ABC-123” so nothing appears, then remove each clause in turn. Good luck!