@@ -119,21 +119,31 @@ for alias in "${aliases[@]}"; do
119119 echo " Alias $alias does not exist, skipping."
120120 continue
121121 fi
122+ echo " Alias $alias exists, removing indices."
122123
123- echo " Alias $alias exists, clearing indices."
124-
125- # Find all indices attached to the alias and clear them
124+ # Find all indices attached to the alias and remove them
126125 indices=$( docker run --rm --network=dependencies_elasticsearch_net appropriate/curl \
127- curl -s -XGET " http://$( elasticsearch_host) /_alias/$alias " | jq -r ' keys | join(",") ' )
126+ curl -s -XGET " http://$( elasticsearch_host) /_alias/$alias " | jq -r ' keys [] ' )
128127
129- echo " Clearing indices $indices "
130- if [ -n " $indices " ]; then
131- docker run --rm --network=dependencies_elasticsearch_net appropriate/curl \
132- curl -XPOST " http://$( elasticsearch_host) /$indices /_delete_by_query" -H " Content-Type: application/json" \
133- -d ' {"query": {"match_all": {}}}'
134- fi
128+ for index in $indices ; do
129+ echo " Checking if index '$index ' exists..."
130+
131+ exists=$( docker run --rm --network=dependencies_elasticsearch_net appropriate/curl \
132+ curl -s -o /dev/null -w " %{http_code}" " http://$( elasticsearch_host) /$index " )
133+
134+ if [ " $exists " -eq 200 ]; then
135+ echo " Deleting index: $index "
136+ docker run --rm --network=dependencies_elasticsearch_net appropriate/curl \
137+ curl -sS -XDELETE " http://$( elasticsearch_host) /$index "
138+ else
139+ echo " Index '$index ' does not exist (status $exists ), skipping."
140+ fi
141+ done
135142done
136143
144+ # Restart event service to ensure index is created
145+ docker service scale ${STACK} _events=0
146+ docker service scale ${STACK} _events=1
137147
138148# Delete all data from metrics
139149# -----------------------------
0 commit comments