ES数据迁移之elasticdump

1、安装步骤

如果出现以下错误:
(1)没有package.json这个文件:可以使用npm init -f命令生成一下
(2)relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libss :
       先安装openssl 命令:yum install -y openssl 然后安装ws 命令:npm install ws
如果安装成功,elasticdump的默认路径在node_modules/elasticdump/bin,首先打开目录:cd node_modules/elasticdump/bin
在此目录下执行下面语句:

2、导入索引模板

elasticdump \
--input=./templates.json \
--output=http://es.com:9200 \
--type=template

3、数据拷贝或迁移:

(1)

--type=analyzer:拷贝analyzer分词
--type=data :拷贝数据
--type=mapping  :拷贝映射(意思是把原始索引的mapping结构迁移给目标索引)
./elasticdump  --input=http://host1:9200/original --output=http://host2:9200/newCopy --type=data 
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=mapping

--all=trueinputoutput里不需要把索引名加上,这样就可以自动把原机器上的所有索引迁移到目标机器:

./elasticdump  --input=http://host1:9200/ --output=http://host2:9200/ --all=true  

 (2)拷贝数据到一个文件:

elasticdump \
  --input=http://host:9200/history_data\
  --output=/home/xtt/my_index_mapping.json \
  --type=mapping
elasticdump \
  --input=http://host:9200/history_data\
  --output=/home/xtt/my_index_mapping.json \
  --type=data

(3)将数据导入多个文件,每个文件大小限定:  

 elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index.json \
  --fileSize=10mb

(4)备份索引到一个gzip:

  elasticdump \
  --input=http://host:9200/history_data \
  --output=$ \
  | gzip > /home/xtt/my_index.json.gz
  

(5)将查询结果备份到一个文件

 elasticdump \
  --input=http://host:9200/history_data \
  --output=/home/xtt/query.json \
  --searchBody='{"query":{"bool":{"filter":{"term":{"camera_id": "0115000013100"}}}}}'

(6)只备份一个shard的数据

  elasticdump \
  --input=http://org_host:9200/history_data \
  --output=http://des_host:9200/my_index_test_ \
  --params='{"preference" : "_shards:0"}'

(7)将json文件映射为索引:

elasticdump \
--input=/home/xtt/my_index.json \
--output=http://host:9200/history_data \
--type=data


部分参考:https://blog.csdn.net/tiantang_1986/article/details/83540739

posted on 2019-02-27 16:52  小驼驼  阅读(3326)  评论(0编辑  收藏  举报