Elasticsearch批量导入数据

时间:2024-03-30 15:21:05

这里用的是curl命令导入,在cmd里面完成的
把curl.exe和要上传的json文件放在同一个文件夹里
Elasticsearch批量导入数据
打开cmd,进入curl解压所在的文件夹,我的路径是E:\1软件\CURL
输入代码:curl -H "Content-Type: application/json" -XPOST "localhost:9200/weibo/date/_bulk?refresh" --data-binary "@Test.json"

代码解释:/weibo/date是输入数据的文件名称,@Test.json是要上传的json文件的名称,注意前面要加@
Elasticsearch批量导入数据
贴一下我的数据格式:(之前只有value值就会导入失败,必要每条数据都加上它的文件名称)
Elasticsearch批量导入数据

运行成这样就是成功了:
Elasticsearch批量导入数据
打开Kibana看一下结果:
Elasticsearch批量导入数据
当然,在这之前还遇到过很多的问题,我总结一下吧!

1."error":{"type":"mapper_parsing_exception","reason":"Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters."Elasticsearch批量导入数据
“_id”是不对的,需要到API里面去设置。因为我的id里面是16进制,是数字和字母的组合,所以导入失败,我直接把“id”里面的“”删除了,所以导入成功
2.{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"}],"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"},"status":400}Elasticsearch批量导入数据
这里的话,是说数据后面需要换行,我没有换行,换行之后就可以了

导入成功之后就可以查看数据了:https://blog.csdn.net/wd2014610/article/details/82426863Elasticsearch批量导入数据
找到“weibo”
Elasticsearch批量导入数据
Elasticsearch批量导入数据
这样就可以搜索导入数据的内容啦
当然,如果想要更高级的搜索过程的话,需要自己另外写代码了