使用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

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

被折叠的 条评论
为什么被折叠?



