@@ -139,7 +139,25 @@ elasticsearch_host() {
139139
140140echo " delete any previously created snapshot if any. This may error on a fresh install with a repository_missing_exception error. Just ignore it."
141141docker run --rm --network=$NETWORK appropriate/curl curl -X DELETE " http://$( elasticsearch_host) /_snapshot/ocrvs"
142- docker run --rm --network=$NETWORK appropriate/curl curl -X DELETE " http://$( elasticsearch_host) /*" -v
142+
143+ # Delete all data from elasticsearch
144+ # -----------------------------------
145+ approved_words=${ES_INDEX_PREFIXES:- " events_ ocrvs-" }
146+ indices=$( docker run --rm --network=$NETWORK appropriate/curl curl -sS -XGET " http://$( elasticsearch_host) /_cat/indices?h=index" )
147+ echo " --------------------------"
148+ echo " 🧹 cleanup for indices: $approved_words from $indices "
149+ echo " --------------------------"
150+ for index in ${indices[@]} ; do
151+ for approved in $approved_words ; do
152+ case " $index " in
153+ " $approved_words " * )
154+ echo " Delete index $index ..."
155+ docker run --rm --network=$NETWORK appropriate/curl curl -sS -XDELETE " http://$( elasticsearch_host) /$index "
156+ break
157+ ;;
158+ esac
159+ done
160+ done
143161
144162echo " Waiting for elasticsearch to restart so that the restore script can find the updated volume."
145163docker service update --force --update-parallelism 1 --update-delay 30s opencrvs_elasticsearch
@@ -239,7 +257,8 @@ sleep 10
239257
240258# Restore all data from a backup into search
241259# -------------------------------------------
242- docker run --rm --network=$NETWORK appropriate/curl curl -X POST -H " Content-Type: application/json;charset=UTF-8" " http://$( elasticsearch_host) /_snapshot/ocrvs/snapshot_$LABEL /_restore?pretty" -d ' { "indices": "ocrvs" }'
260+ json_payload=" {\" indices\" : \" ocrvs-*,events_*\" , \" include_global_state\" : false}"
261+ docker run --rm --network=$NETWORK appropriate/curl curl -X POST -H " Content-Type: application/json;charset=UTF-8" " http://$( elasticsearch_host) /_snapshot/ocrvs/snapshot_$LABEL /_restore?pretty" -d " $json_payload "
243262sleep 10
244263echo " Waiting 1 minute to rotate elasticsearch passwords"
245264echo
0 commit comments