From 8f61b4752934e2e1a476090b778a5d41f881e0f0 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 5 Apr 2018 18:18:35 +0200 Subject: [PATCH] varioux fixes. Upgrade to 5.6 should be ok --- scripts/elastic-upgrade.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/elastic-upgrade.sh b/scripts/elastic-upgrade.sh index b21f72af2..897e3cc54 100755 --- a/scripts/elastic-upgrade.sh +++ b/scripts/elastic-upgrade.sh @@ -50,9 +50,9 @@ config() read -rp "Is fab-manager installed at \"$FM_PATH\"? (y/n) " confirm /dev/null | awk '{s+=$6} END {printf "%.0f", s}') # get all indices local indices=$(curl "$ES_IP:9200/_cat/indices" 2>/dev/null | awk '{print $3}') - + local migration_indices="" for index in $indices # do not surround $indices with quotes do @@ -458,7 +458,7 @@ reindex_indices() echo -e "\nReindex completed, deleting previous index..." for index in $indices # do not surround $indices with quotes do - curl -XDELETE "$ES_IP:9200/$index?pretty" + curl -XDELETE "$ES_IP:9200/$index?pretty" 2>/dev/null done reenable_allocation } @@ -466,10 +466,11 @@ reindex_indices() reindex_final_indices() { local previous=$1 - # get number of documents - local docs=$(curl "$ES_IP:9200/_cat/indices" 2>/dev/null | awk '{s+=$6} END {printf "%.0f", s}') + # get number of documents (from elastic 5.x, docs.count is at column 7) + local docs=$(curl "$ES_IP:9200/_cat/indices" 2>/dev/null | awk '{s+=$7} END {printf "%.0f", s}') # get all indices local indices=$(curl "$ES_IP:9200/_cat/indices" 2>/dev/null | awk '{print $3}') + local final_indices="" for index in $indices # do not surround $indices with quotes do @@ -486,7 +487,9 @@ reindex_final_indices() }' | jq -s add) local final_index=$(echo "$index" | sed "s/\(.*\)_$previous$/\1/") final_indices+="$final_index," + # create the final index with the previous mapping curl -XPUT "http://$ES_IP:9200/$final_index" 2>/dev/null -H 'Content-Type: application/json' -d "$definition" + # reindex data content to the new migration index curl -XPOST "$ES_IP:9200/_reindex?pretty" 2>/dev/null -H 'Content-Type: application/json' -d '{ "source": { "index": "'"$index"'" @@ -496,22 +499,23 @@ reindex_final_indices() } }' done - echo -e "Indices are reindexing, waiting to finish..." + echo "Indices are reindexing. This may take a while, waiting to finish... " # first we wait for all indices states became green wait_for_green_status # then we wait for all documents to be reindexed - local new_docs=$(curl "$ES_IP:9200/_cat/indices?index=$final_indices" 2>/dev/null | awk '{s+=$6} END {printf "%.0f", s}') + local new_docs=$(curl "$ES_IP:9200/_cat/indices?index=$final_indices" 2>/dev/null | awk '{s+=$7} END {printf "%.0f", s}') while [ "$new_docs" != "$docs" ] do echo -ne "\rdocs: $docs, reindexed: $new_docs" sleep 1 - new_docs=$(curl "$ES_IP:9200/_cat/indices?index=$final_indices" 2>/dev/null | awk '{s+=$6} END {printf "%.0f", s}') + new_docs=$(curl "$ES_IP:9200/_cat/indices?index=$final_indices" 2>/dev/null | awk '{s+=$7} END {printf "%.0f", s}') done - echo "\nReindex completed, deleting previous index..." + echo -e "\nReindex completed, deleting previous index..." for index in $indices # do not surround $indices with quotes do curl -XDELETE "$ES_IP:9200/$index?pretty" 2>/dev/null done + reenable_allocation } start_upgrade()