From 6ae5985782c17fe78b3f28bc6f35070b6eff42b3 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Thu, 25 Apr 2024 17:27:45 +0200 Subject: [PATCH] Add script to delete non-aliased indices, keeping newest (RPB-137) --- deleteOldIndices.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 deleteOldIndices.sh diff --git a/deleteOldIndices.sh b/deleteOldIndices.sh new file mode 100644 index 0000000..b1edc89 --- /dev/null +++ b/deleteOldIndices.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euxo pipefail + +# Delete matching non-aliased indices, but keep the newest + +indices=("gnd-rppd*" "resources-rpb*") +for index in "${indices[@]}" +do + curl -s -S -X GET "localhost:9200/_cluster/state?filter_path=metadata.indices.$index.aliases&pretty" | + jq -r '.metadata.indices | to_entries[] | select(.value.aliases | length == 0) | .key' | # no alias + sort | head -n -1 | # don't include the newest index + awk '{print "localhost:9200/"$1"?pretty"}' | + xargs -L 1 curl -s -S -v -X DELETE +done