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

Need to optimize the output of a custom Search API Endpoint in ScriptRunner for Confluence Server


We are using a custom search query with ScriptRunner followed by this article :

The problem we have is that the query returns a lot of information we dont need or its duplicate, like the Content of the page is displayed with 3 different properties (resultExcerpt, content, sanitisedContent).
Our goal is:
1. To make the SearchManager return only the fields/properties we specify, title and content.
2. Optionally, reduce the content length to about 500 characters.

Looking in to the SearchManager interface javadoc, I see there is a method to return only the fields requested 

search (ISearch search, Set<String> requestedFields)
Perform a search with a given criteria, the returns searchResults only have the fields requested in the projection filled out, no other fields are valid in the searchResult.

I could not figure out how I can make the proper

Set<String> requestedFields

I tried to make it work in many ways, but I always get:

When I do .getClass I am getting the default


Here is my pity attempt to make it work, from the Console

import com.atlassian.seraph.auth.DefaultAuthenticatorimport com.atlassian.confluence.user.UserAccessorimport com.atlassian.confluence.user.AuthenticatedUserThreadLocalimport com.atlassian.confluence.spaces.SpaceManagerimport com.atlassian.sal.api.component.ComponentLocator
import groovy.json.JsonBuilderimport groovy.transform.BaseScript
import java.util.HashSet

def searchManager = ComponentLocator.getComponent(SearchManager)
def paramQueryString = "ArticleThatWillBeDeleted"
def query = BooleanQuery.andQuery(new TextQuery(paramQueryString));def sort = new RelevanceSort();def searchFilter = SiteSearchPermissionsSearchFilter.getInstance();def searchContent = new ContentSearch(query, sort, searchFilter, 0100);
Set<String> requestedFields = new HashSet<String>();requestedFields.add("displayTitle");
def searchresult =,requestedFields)
return searchresult.getAll()

Here is a sample of the output I am getting (when I use the JSON builder and call the API directly, because I dont know how to expand the return in the Console

"resultExcerpt": "",
"explain": {
"present": false,
"empty": true
"resultExcerptWithHighlights": "",
"extraFields": {

"displayTitleWithHighlights": ""


Without trying to use the requestedFields, the output looks something like this (I have only paste the first letters of the values)

displayTitle : A
handle : @
lastUpdateDescription :
ownerTitle :
spaceName : E
creatorUser : @
resultExcerpt : t
ownerType :
lastModifier : v
urlPath : /
resultExcerptWithHighlights : t
explain : @
lastModifierUser : @
extraFields : @
lastModificationDate : 2
type : p
content :

creationDate : 2
personalLabels : {
status : c
spaceKey : W
contentVersion : 1
creator : v
displayTitleWithHighlights : A
homePage : F
sanitisedContent : t

I allow the fact that I could have understand that all wrong, so I am open for suggestions to the problem I wanna solve.


0 answers

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events