ElasticSearch大批量数据入库

宗政子辰
2023-12-01

1.bulk批量导入数据

curl 172.17.1.15:9200/_bulk?pretty --data-binary @E:\Bin\Debug\testdata\437714060.json
curl 172.17.1.15:9200/_bulk?pretty --data-binary @E:\Bin\Debug\testdata\743719428.json
curl 172.17.1.15:9200/_bulk?pretty --data-binary @E:\Bin\Debug\testdata\281679894.json
curl 172.17.1.15:9200/_bulk?pretty --data-binary @E:\Bin\Debug\testdata\146257480.json
curl 172.17.1.15:9200/_bulk?pretty --data-binary @E:\Bin\Debug\testdata\892018760.json
但问题是这方法是先定义一定格式的json文件,然后再用curl命令去执行Elasticsearch的_bulk来批量插入,所以得把数据写进json文件,然后再通过批处理,执行文件插入数据, 另外在生成json文件,文件不能过大,过大会报错,所以建议生成10M一个文件

2. github上找到了一个数据导入导出工具

github上找到了一个数据导入导出工具,算是基本上解决了这个问题,直接把数据从原来的index里面取出来然后重新录入到新的index里面,这样省去了数据解析的过程,节约了不少时间。

下面是问题的解决步骤:

首先安装一下elasticsearch-knapsack(数据导入导出工具)

  1. ./bin/plugin -install knapsack -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-knapsack/1.5.2.0/elasticsearch-knapsack-1.5.2.0-plugin.zip  

然后可以通过导出命令导出json格式的数据到系统中的某个文件夹(导出某个index中的数据到指定路径)
  1. curl -XPOST 'localhost:9200/test/_export?path=/tmp/myarchive.zip'  

然后运用导入命令将数据导入进elasticsearch里面
[html] view plain copy
  1. curl -XPOST 'localhost:9200/test/test/_import?path=/tmp/myarchive.zip' 

以下是github地址:

  1. https://github.com/jprante/elasticsearch-knapsack 


 类似资料: