From 72c46eb675349450f49c8e4b80062bf4e639334b Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:37:22 -0700 Subject: [PATCH] auto expand replicas for logtype index (#568) (#570) 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 b54e4eb82..3c7812f44 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 7b9e6e066..5e0eef508 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); } }