elasticsearch数据导入导出

安装工具elasticdump

npm install elasticdump -g

导出匹配数据

// 导出 index 的 mapping 到 .json 文件
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index_mapping.json \
  --type=mapping
// 导出 index 的所有数据到 .json 文件
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index.json \
  --type=data

windows版本

elasticdump --input http://username:pwd@192.168.1.6:9200/demo_idx --output D:/es/index/demo_idx.json --type=mapping
elasticdump --input http://username:pwd@192.168.1.6:9200/demo_idx --output D:/es/index/demo_idx_data.json
--searchBody="{\"query\":{\"match\":{\"dataCode\": \"HRRR_GRID_HOR\"}}}"

导入匹配数据到新搜索引擎

// 从 .json 文件导入 templates 到 ES 
elasticdump \
  --input=./templates.json \
  --output=http://es.com:9200/my_index \
  --type=template

使用docker

docker pull elasticdump/elasticsearch-dump
docker run --rm -ti elasticdump/elasticsearch-dump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=mapping

导入错误

删除索引之后导入报错

C:\Users\Administrator>elasticdump --input D:/es/index/whjc_alarm_idx.json --output http://localhost:9200/whjc_alarm_idx --type=mapping
Tue, 21 Apr 2020 06:58:12 GMT | starting dump
Tue, 21 Apr 2020 06:58:12 GMT | got 1 objects from source file (offset: 0)
Tue, 21 Apr 2020 06:58:12 GMT | Error Emitted => {"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [airportIcaoCode] of different type, current_type [keyword], merged_type [text]"}],"type":"illegal_argument_exception","reason":"mapper [airportIcaoCode] of different type, current_type [keyword], merged_type [text]"}
Tue, 21 Apr 2020 06:58:12 GMT | Error Emitted => {"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [airportIcaoCode] of different type, current_type [keyword], merged_type [text]"}],"type":"illegal_argument_exception","reason":"mapper [airportIcaoCode] of different type, current_type [keyword], merged_type [text]"}
Tue, 21 Apr 2020 06:58:12 GMT | Total Writes: 0
Tue, 21 Apr 2020 06:58:12 GMT | dump ended with error (get phase) => [object Object]

检查system.log日志

org.elasticsearch.ResourceAlreadyExistsException: index [whjc_alarm_idx/v10xLoyST0C9vIQmMLQmfg] already exists

手动删除

DELETE http://localhost:9200/whjc_taf_message_idx
/home/elassandra/data/elasticsearch.data/nodes/0/indices/v10xLoyST0C9vIQmMLQmfg
/home/elassandra/data/data/whjc_alarm_idx

注意次序,重新导入即可
删了文件夹,DELETE命令将无法删除索引

Caused by: org.elasticsearch.gateway.CorruptStateException: org.apache.lucene.index.CorruptIndexException: checksum failed (hardware problem?) : expected=88e357e5 actual=7e684031 (resource=BufferedChecksumIndexInput(SimpleFSIndexInput(path="/home/elassandra/data/elasticsearch.data/nodes/0/indices/AQaVvmfRSieNfN4P5NG0LA/_state/state-0.st")))
	at org.elasticsearch.gateway.MetaDataStateFormat.read(MetaDataStateFormat.java:209)
	at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState(MetaDataStateFormat.java:337)
	... 5 common frames omitted
chown njyjy /home/elassandra/data/elasticsearch.data/nodes/0/indices/AQaVvmfRSieNfN4P5NG0LA -R
java -cp /home/elassandra/lib/lucene-core-7.2.1.jar -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex /home/elassandra/data/elasticsearch.data/nodes/0/indices/AQaVvmfRSieNfN4P5NG0LA/0/index -verbose -exorcise

完全迁移可以迁移文件data/*和配置文件elasticsearch.yml、cassandra.yaml

参考:https://www.npmjs.com/package/elasticdump

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值