From 7f72dc41fbdbe9ad78ff5a7e41fba1ece2d93b82 Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Wed, 13 Sep 2023 03:43:45 +0000 Subject: [PATCH] auto expand replicas for logtype index Signed-off-by: Subhobrata Dey --- .../securityanalytics/logtype/LogTypeService.java | 6 ++++++ .../securityanalytics/util/CustomLogTypeIndices.java | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java b/src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java index 40ec8db74..2be1fce78 100644 --- a/src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java +++ b/src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java @@ -439,10 +439,16 @@ public void ensureConfigIndexIsInitialized(ActionListener listener) { if (state.routingTable().hasIndex(LOG_TYPE_INDEX) == false) { isConfigIndexInitialized = false; + Settings indexSettings = Settings.builder() + .put("index.hidden", true) + .put("index.auto_expand_replicas", "0-all") + .build(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest(); createIndexRequest.settings(logTypeIndexSettings()); createIndexRequest.index(LOG_TYPE_INDEX); createIndexRequest.mapping(logTypeIndexMapping()); + createIndexRequest.settings(indexSettings); createIndexRequest.cause("auto(sap-logtype api)"); client.admin().indices().create(createIndexRequest, new ActionListener<>() { @Override diff --git a/src/main/java/org/opensearch/securityanalytics/util/CustomLogTypeIndices.java b/src/main/java/org/opensearch/securityanalytics/util/CustomLogTypeIndices.java index d858af029..2a065dc57 100644 --- a/src/main/java/org/opensearch/securityanalytics/util/CustomLogTypeIndices.java +++ b/src/main/java/org/opensearch/securityanalytics/util/CustomLogTypeIndices.java @@ -42,9 +42,13 @@ public static String customLogTypeMappings() throws IOException { public void initCustomLogTypeIndex(ActionListener actionListener) throws IOException { if (!customLogTypeIndexExists()) { + Settings indexSettings = Settings.builder() + .put("index.hidden", true) + .put("index.auto_expand_replicas", "0-all") + .build(); CreateIndexRequest indexRequest = new CreateIndexRequest(LogTypeService.LOG_TYPE_INDEX) .mapping(customLogTypeMappings()) - .settings(Settings.builder().put("index.hidden", true).build()); + .settings(indexSettings); client.indices().create(indexRequest, actionListener); } }