记elasticdump 备份数据导出导入

版本:node

elasticsearch 5.5.2git

elasticdump 2.2github

系统 CentOS7.3json

因项目需求 从生产导出一份索引到测试bash

帮助文档 https://github.com/taskrabbit/elasticsearch-dump?utm_source=dbweekly&utm_medium=emailapp

安装 yum install elasticdumpelasticsearch

elasticdump --input=http://localhost:9200 --output=abc.json --type=data Sun, 25 Sep 2016 13:07:15 GMT | starting dump Sun, 25 Sep 2016 13:07:15 GMT | Error Emitted => {"error":{"root_cause":[{"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36}],"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36},"status":400} Sun, 25 Sep 2016 13:07:15 GMT | Total Writes: 0 Sun, 25 Sep 2016 13:07:15 GMT | dump ended with error (get phase) => Error: {"error":{"root_cause":[{"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36}],"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36},"status":400}测试

As a workaround, the following works:3d

elasticdump --input=http://9.11.8.51:9200/apm --output=apm.json --type=data --searchBody '{"query": { "match_all": {} }, "stored_fields": ["*"], "_source": true }'code

elasticdump --input=apm.json --output=http://9.1.8.234:9200/apm --type=data --searchBody '{"query": { "match_all": {} }, "stored_fields": ["*"], "_source": true }'

elasticdump --input=http://9.11.8.52:9200/metric --output=/data/metric.json --type=data --limit=1000 --searchBody '{"query":{"term":{"timestamp": "2018-09-28"}}}' https://github.com/taskrabbit/elasticsearch-dump

 

按时间导出 先导出mapping 在导出数据

#导出mapping
elasticdump --input="http://9.11.8.52:9200/database" --output=/tmp/database/database__mapping.json --type=mapping

#在导出数据  导出7月28号数据
elasticdump   --input=http://9.11.8.52:9200/database --output=/tmp/database/database.json --type=data --limit=1000 --searchBody '{"query":{"term":{"timestamp": "2019-07-28"}}}'

导入

先建立索引

导入mapping

root@ *node* @node3:/root/database# elasticdump --input /root/database/database__mapping.json --output http://9.1.8.234:9200/database --type=mapping
Mon, 29 Jul 2019 09:12:24 GMT | starting dump
Mon, 29 Jul 2019 09:12:24 GMT | got 1 objects from source file (offset: 0)
Mon, 29 Jul 2019 09:12:24 GMT | sent 1 objects to destination elasticsearch, wrote 5
Mon, 29 Jul 2019 09:12:24 GMT | got 0 objects from source file (offset: 1)
Mon, 29 Jul 2019 09:12:24 GMT | Total Writes: 5
Mon, 29 Jul 2019 09:12:24 GMT | dump complete

查看mapping

导入数据

elasticdump --input /root/database/database.json --output http://9.1.8.234:9200/database --type=data

查看数据

相关文章
相关标签/搜索