From 14f937197736148e1ff02a5c59db2b0463814da5 Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Tue, 19 Nov 2024 03:56:14 +0000 Subject: [PATCH] sort matching docs by seq_no Signed-off-by: Subhobrata Dey --- .../kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt index 99bedd46f..cc9e6508c 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt @@ -58,6 +58,7 @@ import org.opensearch.search.aggregations.AggregatorFactories import org.opensearch.search.aggregations.bucket.composite.CompositeAggregationBuilder import org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder import org.opensearch.search.builder.SearchSourceBuilder +import org.opensearch.search.sort.SortOrder import org.opensearch.transport.TransportService import java.time.Instant import java.util.UUID @@ -479,7 +480,7 @@ object BucketLevelMonitorRunner : MonitorRunner() { val queryBuilder = if (input.query.query() == null) BoolQueryBuilder() else QueryBuilders.boolQuery().must(source.query()) queryBuilder.filter(QueryBuilders.termsQuery(fieldName, bucketValues)) - sr.source().query(queryBuilder) + sr.source().query(queryBuilder).sort("_seq_no", SortOrder.DESC) } sr.cancelAfterTimeInterval = TimeValue.timeValueMinutes( getCancelAfterTimeInterval()