使用elasticdump做数据迁移


es版本
[root@localhost bin]# ./elasticdump --help
elasticdump: Import and export tools for elasticsearch
version: 4.6.0

1.elasticdump

安装
su - root
cd /opt
yum install epel-release
yum install nodejs
yum install npm
npm install elasticdump
cd node_modules/elasticdump/bin  后便可以执行操作。

#拷贝analyzer如分词
./elasticdump \
  --input=http://192.168.1.85:9200/db_customer \
  --output=http://192.168.1.118:9200/db_customer \
  --type=analyzer

#拷贝映射
./elasticdump \
  --input=http://192.168.1.85:9200/db_customer \
  --output=http://192.168.1.118:9200/db_customer \
  --type=mapping

#拷贝数据
./elasticdump \
  --input=http://192.168.1.85:9200/db_customer \
  --output=http://192.168.1.118:9200/db_customer \
  --type=data

带验证的导入

./elasticdump \
  --input=http://elastic:elastic@192.168.1.134:29200/db_customer \
  --output=http://elastic:elastic@192.168.1.118:9200/db_customer \
  --type=analyzer

#拷贝映射
./elasticdump \
  --input=http://elastic:elastic@192.168.1.134:29200/db_customer \
  --output=http://elastic:elastic@192.168.1.118:9200/db_customer \
  --type=mapping

#拷贝数据
./elasticdump \
  --input=http://elastic:elastic@192.168.1.134:29200/db_customer \
  --output=http://elastic:elastic@192.168.1.118:9200/db_customer \
  --type=data

 

 


------------------------原封不动的迁移----------------------------------------------
#拷贝分词
./elasticdump --input=http://192.168.1.136:19200/hxl_test --output=http://192.168.1.136:19200/bak01_hxl_test --type=analyzer


#拷贝映射
./elasticdump --input=http://192.168.1.136:19200/hxl_test  --output=http://192.168.1.136:19200/bak01_hxl_test --type=mapping


#拷贝数据
./elasticdump --input=http://192.168.1.136:19200/hxl_test --output=http://192.168.1.136:19200/bak01_hxl_test --type=data

----------------------------提前创建索引后,只迁移数据------------------------
1.提前创建索引,结构可以跟源库的有一定的差异
比如在原来索引的基础上添加了"type": "nested"
2.同步数据
/opt/node_modules/elasticdump/bin/elasticdump --input=http://192.168.1.136:19200/inoculate --output=http://192.168.1.136:19200/inoculate_new --type=data

​遇到的错误:
​/opt/node_modules/elasticdump/lib/processor.js:40
  async _loop (limit, offset, totalWrites) {
        ^^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/opt/node_modules/elasticdump/elasticdump.js:3:28)
[root@yeemiao-oracle-9e96168-prd bin]#
[root@yeemiao-oracle-9e96168-prd bin]# npm install -g n
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
/usr/lib
└── n@6.0.1

[root@yeemiao-oracle-9e96168-prd bin]# /opt/node_modules/elasticdump/bin/elasticdump --input=http://172.17.10.20:19200/child_inocexamine_student --output=http://172.17.10.61:29200/child_inocexamine_student --type=analyzer
/opt/node_modules/elasticdump/lib/processor.js:40
  async _loop (limit, offset, totalWrites) {
        ^^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/opt/node_modules/elasticdump/elasticdump.js:3:28)
    
解决办法:
#升级nodejs
[root@localhost ~]# npm install -g n
[root@localhost ~]# n latest

posted @ 2019-10-16 18:15  slnngk  阅读(2339)  评论(0编辑  收藏  举报