跟我学Elasticsearch(13) 使用bulk进行批量增删改

本文详细介绍Elasticsearch中bulk API的使用方法,包括批量增删改操作的JSON语法,如何在一个请求中组合多种操作,以及注意事项如内存管理和数据量控制。

使用bulk语法可以进行批量增删改操作,bulk语法有严格的要求,每个json串不能换行,两个json串必须换行,下面演示下

#删除
POST /_bulk
{ "delete": { "_index": "test_index", "_type": "test_type", "_id": "1" }} 
#强制创建
POST /_bulk
{ "create": { "_index": "test_index", "_type": "test_type", "_id": "1" }}
{ "test_field":    "create test" }
#不存在则创建,存在则替换,执行put操作
POST /_bulk
{ "index":  { "_index": "test_index", "_type": "test_type", "_id": "1" }}
{ "test_field":    "index test" }
#更新,执行partial update操作
POST /_bulk
{ "update": { "_index": "test_index", "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} }
{ "doc" : {"test_field" : "update test"} }

我们也可以把增删改放在1个请求里面

POST /_bulk
{ "delete": { "_index": "test_index", "_type": "test_type", "_id": "1" }} 
{ "create": { "_index": "test_index", "_type": "test_type", "_id": "1" }}
{ "test_field":    "create test" }
{ "index":  { "_index": "test_index", "_type": "test_t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值