Skip to content

Instantly share code, notes, and snippets.

@danielflira
Last active January 11, 2021 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielflira/90bfb9c76a6b64467703512bd31f6497 to your computer and use it in GitHub Desktop.
Save danielflira/90bfb9c76a6b64467703512bd31f6497 to your computer and use it in GitHub Desktop.
comandos úteis para manutenção do elasticsearch
#!/bin/bash
set -e
export ELASTIC_URL="http://engpro.totvs.com.br:9200"
curl -sL -X GET "${ELASTIC_URL}/_cat/indices" | awk '$1 != "green" {print($3)}' | while read indice; do
echo -n "${indice} zero replicas to zero: "
curl -sL -XPUT "${ELASTIC_URL}/${indice}/_settings" -d '{"number_of_replicas": 0}'
echo
sleep 1
done
curl -sL -X GET "${ELASTIC_URL}/_cat/indices" | awk '$1 == "red" && $2 == "open" {print($3, $2)}' | while read indice status; do
echo -n "${indice} recovery: "
curl -sL -X GET "${ELASTIC_URL}/${indice}/_recovery?pretty&detailed=true"
echo
sleep 1
done
curl -sL -X GET "${ELASTIC_URL}/_cat/indices" | awk '$1 == "red" && $2 == "open" {print($3, $2)}' | while read indice status; do
echo -n "${indice} closing: "
curl -sL -X POST "${ELASTIC_URL}/${indice}/_close"
echo
done
curl -sL -X GET "${ELASTIC_URL}/_cat/indices" | awk '$1 == "close" {print($2)}' | while read indice; do
echo -n "${indice} force new translog: "
curl -sL -X PUT "${ELASTIC_URL}/${indice}/_settings?pretty" -d '{ "index.engine.force_new_translog": true} '
echo
sleep 1
done
curl -sL -X GET "${ELASTIC_URL}/_cat/indices" | awk '$1 == "close" {print($2)}' | while read indice; do
echo -n "${indice} open: "
curl -sL -X POST "${ELASTIC_URL}/${indice}/_open"
echo
done
for indice in `curl -sL -X GET "${ELASTIC_URL}/_cat/indices" | awk '$1 == "red" {print($3)}'`; do
curl -sL -X GET "${ELASTIC_URL}/_cat/indices/${indice}?pretty"
read -p "deseja excluir o indice ${indice} (y/n)? [n] " yesno
if [[ "${yesno}" != "y" ]]; then
continue
fi
echo -n "${indice} closing: "
curl -sL -X POST "${ELASTIC_URL}/${indice}/_close"
echo
echo -n "${indice} removendo: "
curl -sL -X DELETE "${ELASTIC_URL}/${indice}"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment