One - One Code All

Blog Content

使用node的elasticdump做数据迁移

ElasticSearch   2019-05-11 15:33:45
  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. (/opt/node_modules/elasticdump/elasticdump.js:3:28)


 

解决办法:

#升级nodejs

# npm install -g n 
# n latest

 



上一篇:使用jar ftv命令查看搜索jar包中的文件和类
下一篇:PostgreSql日期类型的模糊查询to_char

The minute you think of giving up, think of the reason why you held on so long.