From 551aa0f275da0b6818ef5e747e0d676adb4bde2c Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:56:00 -0700 Subject: [PATCH] set blank response when indexNotFound exception (#1125) (#1126) (cherry picked from commit 65c1519962b5bb99c372df6187b61ceccbeb21eb) Signed-off-by: Riya Saxena Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../correlation/alert/CorrelationAlertService.java | 7 ++++++- 1 file changed, 6 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..e5c43698b 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; @@ -188,7 +189,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); + } } )); }