From c4e3e6cc622f7d1d1d87efcccabffda7cdb28129 Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Wed, 13 Sep 2023 18:19:55 +0000 Subject: [PATCH] auto expand replicas for logtype index (#568) Signed-off-by: Subhobrata Dey (cherry picked from commit 907ed64751948d40d96b1c86f9c3d377798daf8b) --- .../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 4761558da..eeb099e0b 100644 --- a/src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java +++ b/src/main/java/org/opensearch/securityanalytics/logtype/LogTypeService.java @@ -442,10 +442,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 c2aa0d977..21eb460d5 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); } }