Last active
May 17, 2023 07:55
-
-
Save pmint93/683b15ba7d61ab2416b8f7f3174f4f80 to your computer and use it in GitHub Desktop.
Elasticsearch post-start script to automatic update indicies settings (example with docker-compose)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.3" | |
services: | |
elasticsearch: | |
container_name: elasticsearch | |
image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.3.1 | |
restart: unless-stopped | |
ports: | |
- "9200:9200" | |
environment: | |
ES_JAVA_OPTS: "-Xmx2g -Xms2g" | |
bootstrap.memory_lock: "true" | |
discovery.type: "single-node" | |
http.host: "0.0.0.0" | |
action.auto_create_index: "false" | |
network.host: "0.0.0.0" | |
ulimits: | |
nofile: | |
soft: 65536 | |
hard: 65536 | |
memlock: | |
hard: -1 | |
soft: -1 | |
volumes: | |
- /tmp/elasticsearch/data:/var/lib/elasticsearch/data:Z | |
elasticsearch-poststart: | |
image: alpine/curl:latest | |
depends_on: | |
- elasticsearch | |
restart: "no" | |
command: | |
- /bin/sh | |
- -c | |
- | | |
echo "$$(date) - [debug] --------------------" | |
echo "$$(date) - [debug] - ES_HOST: $${ES_HOST}" | |
echo "$$(date) - [debug] - READ_ONLY_ALLOW_DELETE: $${READ_ONLY_ALLOW_DELETE}" | |
echo "$$(date) - [debug] - MAX_RESULT_WINDOWS: $${MAX_RESULT_WINDOWS}" | |
while true; do | |
if [[ "$$(curl --write-out %{http_code} --silent --output /dev/null $${ES_HOST}/_cat/health?h=st)" -eq 200 ]]; then | |
break | |
else | |
echo "$$(date) - [warning] - waiting for $${ES_HOST} to be ready" | |
sleep 5 | |
fi | |
done | |
echo "" | |
echo "$${READ_ONLY_ALLOW_DELETE}," | while read -d, -r pair; do | |
IFS='=' read -r key val <<EOF | |
$${pair} | |
EOF | |
echo "$$(date) - [info] - PUT /$${key}/_settings with index.blocks.read_only_allow_delete=$${val}" | |
curl -XPUT -H "Content-Type: application/json" --silent $${ES_HOST}/$${key}/_settings -d "{\"index.blocks.read_only_allow_delete\": $${val}}" | |
echo "" | |
done | |
echo "" | |
echo "$${MAX_RESULT_WINDOWS}," | while read -d, -r pair; do | |
IFS='=' read -r key val <<EOF | |
$${pair} | |
EOF | |
echo "$$(date) - [info] - PUT /$${key}/_settings with index.max_result_window=$${val}" | |
curl -XPUT -H "Content-Type: application/json" --silent $${ES_HOST}/$${key}/_settings -d "{\"index.max_result_window\": $${val}}" | |
echo "" | |
done | |
environment: | |
ES_HOST: "elasticsearch:9200" | |
READ_ONLY_ALLOW_DELETE: _all=false | |
# READ_ONLY_ALLOW_DELETE: my-index=false,other-index=true | |
MAX_RESULT_WINDOWS: _all=11000 | |
# MAX_RESULT_WINDOWS: my-index=13000,other-index=20000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment