Skip to main content
Example scripts
arrow icon
To homepage
Confluence
Data centre icon
Data Center

Perform a CQL Search in ScriptRunner for Confluence

Tags
Created 1 year ago, Updated 1 month(s) ago
App in script
ScriptRunner For Confluence
ScriptRunner For Confluence
by Adaptavist
Compatibility
compatibility bullet
Confluence (7.15 - 8.6)
compatibility bullet
ScriptRunner For Confluence (7.10.0)
Language |
groovy
import com.atlassian.confluence.api.model.Expansion
import com.atlassian.confluence.api.model.content.Content
import com.atlassian.confluence.api.model.pagination.PageResponse
import com.atlassian.confluence.api.model.pagination.SimplePageRequest
import com.atlassian.confluence.api.model.search.SearchContext
import com.atlassian.confluence.api.service.search.CQLSearchService
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def cqlSearchService = ScriptRunnerImpl.getOsgiService(CQLSearchService)
def maxResults = 100

def cqlQuery = "space = PTC and type = page"

def pageRequest = new SimplePageRequest(0, maxResults)

def searchResult = cqlSearchService.searchContent(cqlQuery, SearchContext.builder().build(), pageRequest, Expansion.combine("space")) as PageResponse<Content>

searchResult.each { result ->
    log.warn "result ===> ${result}"
}
Having an issue with this script?
Report it here