Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

elasticsearch reindex

POST _reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}
Comment

shell script to reindex elasticsearch

#!/bin/bash

#ES_HOST="localhost"
#ES_PORT="9200"
TMP="_v2"
echo "****  Script Execution Started ****"
echo " "
echo "**** Fetching List of Indices Elasticsearch Reindexing ****"
curl -s -X GET 'http://localhost:9200/_cat/indices/%2A?v=&s=index:desc' 

echo " "
sleep 5

indices_list=$(curl -s -X GET 'http://localhost:9200/_cat/indices/%2A?v=&s=index:desc' | awk '{print $3}' | sed -n '1!p')
#indices=$(curl -s "http://${ES_HOST}:${ES_PORT}/_cat/indices/abc_*?h=index" | egrep 'abc_[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{8}*')

# do for all abc elastic indices
count=0
echo "$indices_list"
for index in $indices_list
do
    echo " "
    echo "**** Index No: $count ****"
    echo "**** Present Index we are iterating:  ${index} ****"
    count=`expr $count + 1`
    echo " "
    echo " "
    echo "Reindex process starting for index: $index"
    tmp_index=$index${TMP}
    output=$(curl -s -X PUT "http://localhost:9200/$tmp_index" -H 'Content-Type: application/json' -d'
    {
        "settings" : {
            "index" : {
                "number_of_shards" : 5,
                "number_of_replicas" : 1
            }
        }
    }')
    echo " "
    echo "Temporary index: $tmp_index created with output: $output"
    echo "Starting reindexing elastic data from original index: $index to temporary index: $tmp_index"
    output=$(curl -s -X POST "http://localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
    {
      "source": {
        "index": "'$index'"
      },
      "dest": {
        "index": "'$tmp_index'"
      }
    }
    ')
    echo " "
    echo "Reindexing completed from original index: $index to temporary index: $tmp_index with output: $output"
    echo " "
    echo "Deleting $index"
    output=$(curl -s -X DELETE "http://localhost:9200/$index")
    echo "$index deleted with status: $output"
    echo " "
    echo "Creating index: $index"
    output=$(curl -s -X PUT "http://localhost:9200/$index" -H 'Content-Type: application/json' -d'
    {
        "settings" : {
            "index" : {
                "number_of_shards" : 5,
                "number_of_replicas" : 1
            }
        }
    }')
    echo " "
    echo "Index: $index creation status: $output"
    echo " "
    echo "Starting reindexing elastic data from temporary index: $tmp_index to original index: $index"
    output=$(curl -s -X POST "http://localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
    {
      "source": {
        "index": "'$tmp_index'"
      },
      "dest": {
        "index": "'$index'"
      }
    }
    ')
    echo " "
    echo "Reindexing completed from temporary index:$tmp_index to original index:$index with output: $output"
    echo " "
    echo "Deleting $tmp_index"
    output=$(curl -s -X DELETE "http://localhost:9200/$tmp_index")
    echo "$tmp_index deleted with status: $output"
    echo " "
done

echo " "
sleep 5
echo "**** Fetching List of Indices After Elasticsearch Reindexing ****"
curl -s -X GET 'http://localhost:9200/_cat/indices/%2A?v=&s=index:desc' 
echo " "
sleep 5
echo " "
echo "**** Original indices list ****"
echo "$indices_list"
echo "**** No. of indices in original list: $count ****"
echo " "
count1=0
MIndices_list=$(curl -s -X GET 'http://localhost:9200/_cat/indices/%2A?v=&s=index:desc' | awk '{print $3}' | sed -n '1!p')
echo " "
echo "**** Modified indices list ****"
echo "$MIndices_list"
for j in $MIndices_list
do
     count1=`expr $count1 + 1`
done
echo " "
echo "**** No. of indices in modified list: $count1 ****"
echo "****  Script Execution Ended ****"



Comment

PREVIOUS NEXT
Code Example
Shell :: how to get rid of local git repository 
Shell :: copy folder from ssh to local 
Shell :: wordpress clear cache command line 
Shell :: install react native ubuntu 
Shell :: bash single vs double quotes 
Shell :: install react hot loader 
Shell :: linux dd show progress 
Shell :: git merge main into branch 
Shell :: flask install venv 
Shell :: macos install ruby 
Shell :: ssh custom port fla 
Shell :: cuda install in ubuntu 
Shell :: install formik 
Shell :: powershell suppress error 
Shell :: unable to import wx 
Shell :: brew upgrade casks 
Shell :: How install packages from package.tar.gz on rstudio 
Shell :: new branch not showing in visual studio 
Shell :: como instalar brew en linux 
Shell :: jitsi run pod ios app !] Invalid `Podfile` file: cannot load such fil 
Shell :: make file powershell 
Shell :: how to install nvm in ubuntu 18.04 
Shell :: electron app any website 
Shell :: remove commits from github 
Shell :: npm install --save-dev @angular/cli@latest 
Shell :: how to find all the dir in current working directory in linux 
Shell :: how to change folder case sensitivity windows 10 all subfolder 
Shell :: bash replace string 
Shell :: windows change hostname 
Shell :: install radeon drivers ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =