elasticsearch bulk数据--ES批量导入json数据
来源:互联网 发布:网络专业的职业规划 编辑:程序博客网 时间:2024/06/05 14:24
一、Bulk API
官网给出的介绍:https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-bulk.html
The REST API endpoint is /_bulk, and it expects the following newline delimited JSON (NDJSON) structure:
action_and_meta_data\noptional_source\naction_and_meta_data\noptional_source\n....action_and_meta_data\noptional_source\n
也就是说每一个操作都有2行数据组成,末尾要回车换行。第一行用来说明操作命令和原数据、第二行是自定义的选项.举个例子,同时执行插入2条数据、删除一条数据。
{ "create" : { "_index" : "blog", "_type" : "article", "_id" : "3" }}{ "title":"title1","posttime":"2016-07-02","content":"内容一" }{ "create" : { "_index" : "blog", "_type" : "article", "_id" : "4" }}{ "title":"title2","posttime":"2016-07-03","content":"内容2" }{ "delete":{"_index" : "blog", "_type" : "article", "_id" : "1" }}
官网的解释和例子:
Because this format uses literal \n's as delimiters, please be sure that the JSON actions and sources are not pretty printed. Here is an example of a correct sequence of bulk commands:
POST _bulk{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }{ "field1" : "value1" }{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }{ "field1" : "value3" }{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }{ "doc" : {"field2" : "value2"} }
二、把数据保存在文件中的提交方法。 官网的介绍和说明:
If you’re providing text file input to curl, you must use the --data-binary flag instead of plain -d. The latter doesn’t preserve newlines. Example:
$ cat requests{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }{ "field1" : "value1" }$ curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@requests"
具体例子: 把下面的数据保存在文件request中,然后使用命令提交:
vim retuqestcurl -XPOST '192.168.0.153:9200/_bulk' --data-binary @request
{ "index" : { "_index" : "test_index", "_type" : "chen", "_id" : "1" } }{ "field1" : "value1" }{ "index" : { "_index" : "test_index", "_type" : "chen", "_id" : "2" } }{ "field1" : "value2" }{ "index" : { "_index" : "test_index", "_type" : "chen", "_id" : "3" } }{ "field1" : "value3" }
看看有没有提交成功:
curl -XGET 'http://192.168.0.153:9200/test_index/chen/1?pretty'{ "_index" : "test_index", "_type" : "chen", "_id" : "1", "_version" : 2, "found" : true, "_source" : { "field1" : "value1" }}
ok,提交成功。
- elasticsearch bulk数据--ES批量导入json数据
- elasticsearch 使用bulk导入数据
- bulk insert批量数据导入
- Elasticsearch 批量导入数据
- elasticsearch 批量导入数据
- BULK INSERT 实现批量数据导入
- sql server Bulk 批量导入大量数据
- SQL Server Bulk Insert批量数据导入
- SQL Server Bulk Insert批量数据导入
- Bulk insert 批量导入数据的限制
- SQL Server Bulk Insert 批量数据导入
- ELK研究(一):elasticsearch java api接口操作ES集群 ---TransportClient的使用介绍 bulk批量提交数据
- ELK研究(一):elasticsearch java api接口操作ES集群 ---TransportClient的使用介绍 bulk批量提交数据
- java+elasticsearch批量导入数据
- 向ElasticSearch批量导入数据
- (总结) SQL Server Bulk Insert 批量数据导入
- (总结) SQL Server Bulk Insert 批量数据导入
- (总结) SQL Server Bulk Insert 批量数据导入
- 【React】React+Redux+Ajax 点餐项目 完整流程【一】
- java实现utf-8与GB2312编码的转换
- CentOS7虚拟机网络的配置
- 【MyBatis】什么是mybatis,mybatis有什么特点(一)
- 网络HTTP、TCP、UDP、Socket 知识总结
- elasticsearch bulk数据--ES批量导入json数据
- Android之NDK与C++的环境变量
- Qt之QSS(动态属性)【转】
- Glide的变换(美图效果)
- 完成FFmepg的移植,编译ffmpeg4Android
- lamnda函数--c++11中的匿名函数
- C++分布式实时应用框架——系统管理模块
- Tomcat 修改/webapps/ROOT发布路径(Linux和windows环境)
- Generate Parentheses