Skip to content

Commit

Permalink
enable users to reconfigure ES port
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyzhang committed Mar 27, 2017
1 parent c251ebd commit bcba12e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions bash/es_reindex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Description :
## --
## Created : <2017-03-27>
## Updated: Time-stamp: <2017-03-27 14:01:46>
## Updated: Time-stamp: <2017-03-27 14:11:16>
##-------------------------------------------------------------------
old_index_name=${1?}

Expand All @@ -15,8 +15,9 @@ if [ -z "$new_index_name" ]; then
fi
shard_count=${3:-5}
replica_count=${4:-1}

es_ip=${5:-""}
es_port=${6:-"9200"}

if [ -z "$es_ip" ]; then
es_ip=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
fi
Expand All @@ -26,10 +27,10 @@ alias_index_name=$(echo "$old_index_name" | sed 's/-index//g')
echo "old_index_name: $old_index_name, new_index_name: $new_index_name"

echo "List all indices"
time curl -XGET "http://${es_ip}:9200/_cat/indices?v"
time curl -XGET "http://${es_ip}:${es_port}/_cat/indices?v"

echo "create new index with proper shards and replicas"
time curl -XPUT "http://${es_ip}:9200/${new_index_name}?pretty" -d "
time curl -XPUT "http://${es_ip}:${es_port}/${new_index_name}?pretty" -d "
{
\"settings\" : {
\"index\" : {
Expand All @@ -40,10 +41,10 @@ time curl -XPUT "http://${es_ip}:9200/${new_index_name}?pretty" -d "
}"

echo "Get the setting of the new index"
time curl -XGET "http://${es_ip}:9200/${new_index_name}/_settings?pretty"
time curl -XGET "http://${es_ip}:${es_port}/${new_index_name}/_settings?pretty"

echo "Reindex index. Attention: this will take a very long time, if the index is big"
time curl -XPOST "http://${es_ip}:9200/_reindex?pretty" -d "
time curl -XPOST "http://${es_ip}:${es_port}/_reindex?pretty" -d "
{
\"conflicts\": \"proceed\",
\"source\": {
Expand All @@ -57,10 +58,10 @@ time curl -XPOST "http://${es_ip}:9200/_reindex?pretty" -d "

# We can start a new terminal and check reindex status
echo "Get all re-index tasks"
time curl -XGET "http://${es_ip}:9200/_tasks?detailed=true&actions=*reindex&pretty"
time curl -XGET "http://${es_ip}:${es_port}/_tasks?detailed=true&actions=*reindex&pretty"

echo "Add index to existing alias and remove old index from that alias. alias: $alias_index_name"
time curl -XPOST "http://${es_ip}:9200/_aliases" -d "
time curl -XPOST "http://${es_ip}:${es_port}/_aliases" -d "
{
\"actions\": [
{ \"remove\": {
Expand All @@ -75,12 +76,12 @@ time curl -XPOST "http://${es_ip}:9200/_aliases" -d "
}"

# List alias
curl -XPGET "http://${es_ip}:9200/_aliases?pretty" | grep -C 10 "$(echo "$old_index_name" | sed "s/.*-index-//g")"
curl -XPGET "http://${es_ip}:${es_port}/_aliases?pretty" | grep -C 10 "$(echo "$old_index_name" | sed "s/.*-index-//g")"

# Close index
curl -XPOST "http://${es_ip}:9200/${old_index_name}/_close"
curl -XPOST "http://${es_ip}:${es_port}/${old_index_name}/_close"

# Delete index
# curl -XDELETE "http://${es_ip}:9200/${old_index_name}?pretty"
# curl -XDELETE "http://${es_ip}:${es_port}/${old_index_name}?pretty"

## File : es_reindex.sh ends

0 comments on commit bcba12e

Please sign in to comment.