From a73893671fd7294fdb46f94bee8139af5074b93d Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Mon, 1 Jul 2024 14:02:46 -0700 Subject: [PATCH] index not found exception response as emptylist for correlations Signed-off-by: Riya Saxena --- .../correlation/alert/CorrelationAlertService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/securityanalytics/correlation/alert/CorrelationAlertService.java b/src/main/java/org/opensearch/securityanalytics/correlation/alert/CorrelationAlertService.java index 54c09d29a..23a3df18b 100644 --- a/src/main/java/org/opensearch/securityanalytics/correlation/alert/CorrelationAlertService.java +++ b/src/main/java/org/opensearch/securityanalytics/correlation/alert/CorrelationAlertService.java @@ -26,6 +26,7 @@ import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; +import org.opensearch.index.IndexNotFoundException; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.QueryBuilders; import org.opensearch.index.query.TermsQueryBuilder; @@ -40,6 +41,8 @@ import org.opensearch.securityanalytics.action.AckCorrelationAlertsResponse; import org.opensearch.securityanalytics.action.GetCorrelationAlertsResponse; import org.opensearch.securityanalytics.util.CorrelationIndices; +import org.opensearch.securityanalytics.util.CorrelationRuleIndices; + import java.io.IOException; import java.time.Instant; import java.util.List; @@ -188,7 +191,11 @@ public void getCorrelationAlerts(String ruleId, Table tableProp, ActionListener< }, e -> { log.error("Search request to fetch correlation alerts failed", e); - listener.onFailure(e); + if (e instanceof IndexNotFoundException) { + listener.onResponse(new GetCorrelationAlertsResponse(Collections.emptyList(), 0)); + } else { + listener.onFailure(e); + } } )); }