elasticsearch dump 教程

巫马淳
2023-12-01

下载安装

首先需要自行下载并安装node。
然后下载elasticsearch-dump,elasticsearch-dump-master.tar.gz然后解压:tar -xvf elasticsearch-dump-master.tar.gz -C ~/app/
然后执行sudo ln -s /home/iie4bu/app/elasticsearch-dump-master/bin/elasticdump /usr/local/bin/,这样就可以直接使用elasticdump

命令

导出数据,包括mapping和data

elasticdump --input http://192.168.171.45:9201/people --output=/mnt/sdb/people-mapping.json --type=mapping
elasticdump --input http://192.168.171.45:9201/people --output=/mnt/sdb/people-data.json --type=data

导入数据

导入的数据格式为:

{"_index": "test", "_type": "_doc", "_id": "9487135226108073440", "_score": null, "_source": {"name": "tom", "age": 17}}
{"_index": "test", "_type": "_doc", "_id": "9487135226123423444", "_score": null, "_source": {"name": "tom", "age": 10}}
{"_index": "test", "_type": "_doc", "_id": "9487135226145768945", "_score": null, "_source": {"name": "tom", "age": 18}}
{"_index": "test", "_type": "_doc", "_id": "9487135226108045678", "_score": null, "_source": {"name": "tom", "age": 19}}

导入命令

./elasticdump --input="./data.json" --output="http://10.26.120.51:9200/{索引名}/{type}" 

在命令中如果输入{索引名}{type},那么就会覆盖文件里面的{索引名}{type}

 类似资料: