From 2d558877d7b226122ac0eff36b4adae6f13b0697 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Flores?= <raphael.flores@inrae.fr>
Date: Mon, 9 Jan 2023 16:37:56 +0100
Subject: [PATCH] Set 1 replica for production indices. DBA-1198.

---
 docker-compose.yml |  6 +++---
 scripts/harvest.sh | 12 ++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index 9b18aa0f..ebab3fc2 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,16 +1,16 @@
 version: '3.3'
 services:
   elasticsearch:
-    image: docker.elastic.co/elasticsearch/elasticsearch:7.13.2
+    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6
     container_name: elasticsearch-faidare
     environment:
       - discovery.type=single-node
-      - "ES_JAVA_OPTS=-Dlog4j2.formatMsgNoLookups=true"
+      - "ES_JAVA_OPTS=-Dlog4j2.formatMsgNoLookups=true -Xms2g -Xmx2g -XX:ParallelGCThreads=2"
     ports:
       - 9200:9200
 
   kibana:
-    image: docker.elastic.co/kibana/kibana:7.13.2
+    image: docker.elastic.co/kibana/kibana:7.17.6
     container_name: kibana-faidare
     environment:
       - "ELASTICSEARCH_URL=http://elasticsearch:9200"
diff --git a/scripts/harvest.sh b/scripts/harvest.sh
index 564d94ad..471d0079 100755
--- a/scripts/harvest.sh
+++ b/scripts/harvest.sh
@@ -249,6 +249,18 @@ for DOCUMENT_TYPE in ${DOCUMENT_TYPES}; do
 		check_acknowledgment "${LOG}" "create aliase"
 	done
 
+	if [ "$ENV" == "prod" ]; then
+		echo ; echo "Update replica setting: ${INDEX_PATTERN}-*"
+		LOG=$(curl -s -X PUT "${ES_HOST}:${ES_PORT}/${INDEX_PATTERN}-*/_settings?pretty" -H 'Content-Type: application/json' -d"
+			{
+				\"index\" : {
+					\"number_of_replicas\" : 1
+				}
+			}
+		")
+		check_acknowledgment "${LOG}" "updating replicas setting for pattern ${INDEX_PATTERN}-*"
+	fi
+
 	# Delete all but last created indices (thanks to the timestamp suffix)
 	echo -e "* Delete old indices ${INDEX_PATTERN} (to avoid accumulation over time):"
 	OLD_INDICES=$(curl -sf -XGET "${ES_HOST}:${ES_PORT}/_cat/indices/${INDEX_PATTERN}*?h=index" | sort | head -n -1)
-- 
GitLab