From 8d19912fe1515a515b3d6a4c3f46064ab8047bb0 Mon Sep 17 00:00:00 2001
From: Megha Goyal <56077967+goyamegh@users.noreply.github.com>
Date: Wed, 14 Feb 2024 14:54:41 -0800
Subject: [PATCH] Fail the flow the when detectot type is missing in the log
 types index (#845)

Signed-off-by: Megha Goyal <goyamegh@amazon.com>
---
 .../correlation/VectorEmbeddingsEngine.java                  | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java b/src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java
index 9a423f6fb..0f9866766 100644
--- a/src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java
+++ b/src/main/java/org/opensearch/securityanalytics/correlation/VectorEmbeddingsEngine.java
@@ -229,6 +229,11 @@ public void onFailure(Exception e) {
     }
 
     public void insertOrphanFindings(String detectorType, Finding finding, float timestampFeature, Map<String, CustomLogType> logTypes) {
+        if (logTypes.get(detectorType) == null) {
+            log.error("LogTypes Index is missing the detector type {}", detectorType);
+            correlateFindingAction.onFailures(new OpenSearchStatusException("LogTypes Index is missing the detector type", RestStatus.INTERNAL_SERVER_ERROR));
+        }
+
         Map<String, Object> tags = logTypes.get(detectorType).getTags();
         String correlationId = tags.get("correlation_id").toString();