elasticsearch 批量导入数据
发布日期:2021-05-07 04:26:46 浏览次数:20 分类:精选文章

本文共 665 字,大约阅读时间需要 2 分钟。

环境

虚拟机:centos7

操作系统:win7
elasticsearch:5.4.3

摘要

假设你有一批现成的数据,比如:,你先把其复制保存在文件名为accounts.json的文件中。

这里特别注意最后一行数据一定要有换行,否则最后那条数据不会插入数据库。

上传文件

accounts.json文件上传到服务器。(我默认你是启动了elasticsearch服务的)

接着在accounts.json目录下,执行以下命令:

curl -u elastic:changeme -H "Content-Type: application/json" -XPOST '192.168.116.19:9200/bank/account/_bulk?pretty&refresh' --data-binary "@accounts.json"

我这里有-u elastic:changeme,是因为我安装了x-pack,所以需要,要是你没有安装,就不需要。

接着在执行http://192.168.116.19:9200/_cat/indices?v查看:

部分信息如下:

health status index uuid pri rep docs.count docs.deleted store.size pri.store.sizegreen  open bank -ais07NBQm6kK_ZqihP6xQ 5 1 1000 0 1.2mb 640.2kb

我们需要查看docs.count数字,表示你目前库里面有多少条数据

上一篇:elasticsearch之Document APIs【Reading and Writing documents】
下一篇:elasticsearch for java之Document APIs【增删改查】

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月11日 17时10分53秒