elasticdump 导出 导入 elasticsearch

张映 发表于 2018-05-04

分类目录: elasticsearch, 服务器相关

标签:, , ,

elasticdump是比较好用的es数据导出导入工具。

1,安装elasticdump

# npm install elasticdump -g

2,导出es数据

# elasticdump \
 --input=http://localhost:9200/pinyin \
 --output=/Users/zhangying/test/pinyin.json \
 --type=data

3,导入es数据

# elasticdump \
--input=./pinyin.json \
--output=http://localhost:9200 \
--type=data

Thu, 03 May 2018 09:52:02 GMT | starting dump
Thu, 03 May 2018 09:52:02 GMT | got 4 objects from source file (offset: 0)
Thu, 03 May 2018 09:52:02 GMT | sent 4 objects to destination elasticsearch, wrote 4
Thu, 03 May 2018 09:52:02 GMT | got 0 objects from source file (offset: 4)
Thu, 03 May 2018 09:52:02 GMT | Total Writes: 4
Thu, 03 May 2018 09:52:02 GMT | dump complete

网上有说用curl也可以,curl -XPOST 'http://localhost:9200/_bulk?pretty' \
-H "Content-Type: application/json" \
--data-binary @pinyin.json,经尝试不成功报以下错误

Malformed action/metadata line [1], expected START_OBJECT or END_OBJECT but found [VALUE_STRING]

4,大数据拆分

# sed -n '1,2p' pinyin.json > pinyin1.json  //前二行放一个文件
# sed -n '3,4p' pinyin.json > pinyin2.json  //后二行放一个文件

如果数据太大,可以进行拆分,避免导入时挂掉。



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/server/1907.html