Skip to content

Commit

Permalink
change terms query clause on indices to list of should clauses as ind…
Browse files Browse the repository at this point in the history
…ex is a text field in query index mapping

Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep committed Jan 11, 2024
1 parent 8167767 commit 27a6ec4
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,13 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
}
concreteIndicesSeenSoFar.addAll(concreteIndices)
val updatedIndexName = indexName.replace("*", "_")
// lastUpdatedIndexName = updatedIndexName
val conflictingFields = monitorCtx.docLevelMonitorQueries!!.getAllConflictingFields(
monitorCtx.clusterService!!.state(),
concreteIndices
)

concreteIndices.forEach { concreteIndexName ->
// Prepare lastRunContext for each index
// lastConcreteIndexName = concreteIndexName
val indexLastRunContext = lastRunContext.getOrPut(concreteIndexName) {
val isIndexCreatedRecently = createdRecently(
monitor,
Expand Down Expand Up @@ -252,7 +250,7 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
}
}
/* if all indices are covered still in-memory docs size limit is not breached we would need to submit
the percolate query at the end*/
the percolate query at the end */
if (transformedDocs.isNotEmpty()) {
performPercolateQueryAndResetCounters(
monitorCtx,
Expand Down Expand Up @@ -772,7 +770,7 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
monitorInputIndices: List<String>,
): SearchHits {
val indices = docs.stream().map { it.second.indexName }.distinct().collect(Collectors.toList())
val boolQueryBuilder = BoolQueryBuilder().must(QueryBuilders.termsQuery("index", indices))
val boolQueryBuilder = BoolQueryBuilder().must(buildShouldClausesOverPerIndexMatchQueries(indices))
val percolateQueryBuilder =
PercolateQueryBuilderExt("query", docs.map { it.second.docSource }, XContentType.JSON)
if (monitor.id.isNotEmpty()) {
Expand Down Expand Up @@ -823,6 +821,12 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
}
return response.hits
}
/** we cannot use terms query because `index` field's mapping is of type TEXT and not keyword. Refer doc-level-queries.json*/
private fun buildShouldClausesOverPerIndexMatchQueries(indices: List<String>): BoolQueryBuilder {
val boolQueryBuilder = QueryBuilders.boolQuery()
indices.forEach { boolQueryBuilder.should(QueryBuilders.matchQuery("index", it)) }
return boolQueryBuilder
}

/** Transform field names and index names in all the search hits to format required to run percolate search against them.
* Hits are transformed using method transformDocumentFieldNames() */
Expand Down

0 comments on commit 27a6ec4

Please sign in to comment.