Migrate Elasticsearch Data

Rizky Ramadhan
2 min readDec 3, 2020

Hi everyone!

in this time, i want to show u how migrate analyzer, mapping, and data from one elasticsearch-host to another elasticsearch-host

requirement:

  • npm
  • elasticdump (npm package)
  • bashscript

in this case i have 2 different elasticsearch-host

  • 192.168.0.1:9201 (there are data)
  • 192.168.5.1:9201 (empty data)

first step:

  1. Install npm on operating system on centos, you can choose the version of nodejs on official website https://nodejs.org/en/download/package-manager/
$ curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash - 
$ sudo yum install nodejs
$ node --version
$ npm --version

2. Install elasticdump with root permission

$ sudo npm install elasticdump -g

for detail u can see in this reference https://github.com/elasticsearch-dump/elasticsearch-dump

3. Create Bascript to looping

$ touch migrateElastic.sh

then editmigrateElastic.shwith nano editor

$ nano migrateElastic.sh

follow this bashcript

#!/binh/sh
indexes=(
index1
index2
index3
)
for i in "${indexes[@]}" ; doelasticdump \
--input=http://192.168.0.1:9201/$i \
--output=http://192.168.5.1:9201/$i \
--type=analyzer

elasticdump \
--input=http://192.168.0.1:9201/$i \
--output=http://192.168.5.1:9201/$i \
--type=mapping
elasticdump \
--input=http://192.168.0.1:9201/$i \
--output=http://192.168.5.1:9201/$i \
--type=data
done

for bashscript explaining

4. Give migrateElastic.sh executable permission

$ chmod +x migrateElastic.sh

5. run bashscript

$ ./migrateElastic.sh

we can see the process of migrating data

6. Check your indexes by accessing http://192.168.5.1:9201/_cat/indices

this example index show from webpage on browser

green open filebeat-7.0.1-2020.10.01-000002    tBBKF7cqTKODSxp3e8K9LQ 1 1      0 0    566b    283b
green open filebeat-7.0.1-2020.09.01-000001 _91t8h-IQJyjaOaPkt998A 1 1 167927 0 104.2mb 52.1mb
green open ilm-history-1-000004 HanK-SFEQSuyQxN4wFuczw 1 1 26 0 26.5kb 13.2kb
green open ilm-history-1-000002 WIgm_erDThCnEfMOtklyAA 1 1 26 0 26.5kb 13.2kb
green open ilm-history-1-000003 x3uG9WdBTRitfLDGn2LiPg 1 1 26 0 26.4kb 13.2kb
green open ilm-history-1-000001 jRZjZTipRY6x1as7R5YFqQ 1 1 30 0 70.3kb 35.1kb

--

--