版本: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
查看數據