1. elasticdump 安装
- yum -y install elasticdump
2.elasticdump 使用
elasticdump
提供了多种导入导出数据的方式,可以 index <-> index 、 index <-> .json 文件,还支持将 index 查询结果导出到 .json 文件。执行的命令也很简单,只需指定数据来源 input
、数据输出 output
、数据类型 type
即可。
2.1 支持导入导出的type
列表
type | 说明 |
---|---|
settings | 对应 es 中的 settings |
analyzer | 对应 es 中的 analyzer |
data | es 查询出来的数据 |
mapping | 对应 es 中的 mapping |
alias | 对应 es 中的 alias |
template | 对应 es 中的 template |
2.2 es数据的导入导出
2.2.1 导入导出命令
- 导出数据到 .json 文件:
// 导出 index 的 mapping 到 .json 文件
elasticdump \
--input=http://username:password@http:port/my_index \
--output=./my_index.json \
--type=mapping
// 导出 index 的所有数据到 .json 文件
elasticdump \
--input=http://username:password@http:port/my_index \
--output=./my_index.json \
--type=data
- 从json导入
-
// 从.json 文件导入 mapping 到ES elasticdump \ --input=./my_index.json \ --output=http://username:password@http:port \ --type=mapping // 从 .json 文件导入 my_index 到 ES elasticdump \ --input=./my_index.json \ --output=http://username:password@http:port \ --type=data
- 导出报错
- 暂时只发现导出data报错
elasticdump \
--input=http://username:password@localhost:9200/my_index \
--output=./my_index.json
--type=data
报错如下
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}
报错原因
- elasticsearch版本是5.3,然后elasticdump的版本elasticdump 2.2.0
解决办法
1,修改导出语句
elasticdump \
--input=http://username:password@http_ip:port/my_index \
--output ./my_index.json \
--searchBody='{"query": { "match_all": {} }, "stored_fields": ["*"], "_source": true }' \
--type=data