From 95180cadd57f528fd7c2d1a3bb15248b41416d15 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Wed, 27 Sep 2023 16:05:10 -0700 Subject: [PATCH] Improve SegRep support for query and bucket level monitors Signed-off-by: Ashish Agrawal --- .../main/kotlin/org/opensearch/alerting/InputService.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt b/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt index 39d6b0e48..aa385d989 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt @@ -20,6 +20,7 @@ import org.opensearch.alerting.util.getRoleFilterEnabled import org.opensearch.alerting.util.use import org.opensearch.alerting.workflow.WorkflowRunContext import org.opensearch.client.Client +import org.opensearch.cluster.routing.Preference import org.opensearch.cluster.service.ClusterService import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.common.settings.Settings @@ -100,7 +101,9 @@ class InputService( .newInstance(searchParams) .execute() - val searchRequest = SearchRequest().indices(*input.indices.toTypedArray()) + val searchRequest = SearchRequest() + .indices(*input.indices.toTypedArray()) + .preference(Preference.PRIMARY_FIRST.type()) XContentType.JSON.xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, searchSource).use { searchRequest.source(SearchSourceBuilder.fromXContent(it)) } @@ -192,7 +195,9 @@ class InputService( .newInstance(searchParams) .execute() - val searchRequest = SearchRequest().indices(*input.indices.toTypedArray()) + val searchRequest = SearchRequest() + .indices(*input.indices.toTypedArray()) + .preference(Preference.PRIMARY_FIRST.type()) XContentType.JSON.xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, searchSource).use { searchRequest.source(SearchSourceBuilder.fromXContent(it)) }