From 0bc494ab8daf2f21222cd8b2f5ac245c0693ecb2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 25 Oct 2024 16:58:49 +0000 Subject: [PATCH] [Bug] Add exists check for IOCs index. (#1392) * Added check to prevent resource_already_exists_exception when indexing more than 10k iocs. Signed-off-by: AWSHurneyt * Changed log message. Signed-off-by: AWSHurneyt --------- Signed-off-by: AWSHurneyt (cherry picked from commit 4432b36a2f97e312f1ef3db2e900e6f9071b3fac) Signed-off-by: github-actions[bot] --- .../securityanalytics/services/STIX2IOCFeedStore.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java b/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java index 0d545f5be..695a9d65a 100644 --- a/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java +++ b/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.OpenSearchException; +import org.opensearch.ResourceAlreadyExistsException; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.StepListener; import org.opensearch.action.admin.indices.create.CreateIndexRequest; @@ -35,6 +36,7 @@ import org.opensearch.securityanalytics.threatIntel.common.StashedThreadContext; import org.opensearch.securityanalytics.threatIntel.model.DefaultIocStoreConfig; import org.opensearch.securityanalytics.threatIntel.model.SATIFSourceConfig; +import org.opensearch.transport.RemoteTransportException; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -250,6 +252,11 @@ private void initFeedIndex(String feedIndexName, ActionListener { + if (e instanceof ResourceAlreadyExistsException || (e instanceof RemoteTransportException && e.getCause() instanceof ResourceAlreadyExistsException)) { + log.debug("index {} already exist", feedIndexName); + listener.onResponse(null); + return; + } log.error("Failed to create system index {}", feedIndexName); listener.onFailure(e); }