Skip to content

Commit

Permalink
rename percolate query execution method
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep committed Dec 20, 2023
1 parent c97b8fb commit a2c72d0
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
}

if (transformedDocs.isNotEmpty()) {
val matchedQueriesForDocs = getMatchedQueries(
val percolateQueryResponseHits = runPercolateQueryOnTransformedDocs(
monitorCtx,
transformedDocs.map { it.second },
monitor,
Expand All @@ -639,7 +639,7 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
concreteIndexName
)

matchedQueriesForDocs.forEach { hit ->
percolateQueryResponseHits.forEach { hit ->
val id = hit.id
.replace("_${indexName}_${monitor.id}", "")
.replace("_${concreteIndexName}_${monitor.id}", "")
Expand Down Expand Up @@ -698,7 +698,8 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
return response.hits
}

private suspend fun getMatchedQueries(
/** Executes percolate query on the docs against the monitor's query index and return the hits from the search response*/
private suspend fun runPercolateQueryOnTransformedDocs(
monitorCtx: MonitorRunnerExecutionContext,
docs: List<BytesReference>,
monitor: Monitor,
Expand Down Expand Up @@ -727,20 +728,21 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
val searchSourceBuilder = SearchSourceBuilder()
searchSourceBuilder.query(boolQueryBuilder)
searchRequest.source(searchSourceBuilder)

logger.debug("Monitor ${monitor.id}: Executing percolate query for docs from source index $index against query index $queryIndex")
var response: SearchResponse
try {
response = monitorCtx.client!!.suspendUntil {
monitorCtx.client!!.execute(SearchAction.INSTANCE, searchRequest, it)
}
} catch (e: Exception) {
throw IllegalStateException(
"Failed to run percolate search for sourceIndex [$index] and queryIndex [$queryIndex] for ${docs.size} document(s)", e
"Monitor ${monitor.id}: Failed to run percolate search for sourceIndex [$index] " +
"and queryIndex [$queryIndex] for ${docs.size} document(s)", e
)
}

if (response.status() !== RestStatus.OK) {
throw IOException("Failed to search percolate index: $queryIndex")
throw IOException("Failed to search percolate index: $queryIndex. Response status is ${response.status()}")
}
return response.hits
}
Expand Down

0 comments on commit a2c72d0

Please sign in to comment.