架构师成长记_第八周_19_ES- 批量操作 bulk
Posted _大木_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了架构师成长记_第八周_19_ES- 批量操作 bulk相关的知识,希望对你有一定的参考价值。
文章目录
ES- 批量操作 bulk
1. bulk 之 create (批量新增)
1.1 第一种写法
POST: http://192.168.92.140:9200/_bulk
"create": "_index": "shop2" ,"_type":"_doc","_id":"2001"
"id": "2001", "nickname":"name-2001"
"create": "_index": "shop2" ,"_type":"_doc","_id":"2002"
"id": "2002", "nickname":"name-2002"
"create": "_index": "shop2" ,"_type":"_doc","_id":"2003"
"id": "2003", "nickname":"name-2003"
1.2 第二种写法
POST: http://192.168.92.140:9200/shop2/_doc/_bulk
"create": "_id":"2101"
"id": "2101", "nickname":"name-2101"
"create": "_id":"2104"
"id": "2104", "nickname":"name-2104"
PS: 批量新增注意:
- 输入的语法: 每行都需要进行换行处理, 最后一行也是
- 在新增的时候当出现的重复的字段会报409错误, 但是并不会影响其他的新增操作.
2. bulk 之 index (覆盖新增)
PS: 和create同样是新增操作, 不同的是, 当id出现重名的时候, index可以进行覆盖处理, 而create则会进行报错.
POST: http://192.168.92.140:9200/shop2/_doc/_bulk
"index": "_id":"2111"
"id": "2111", "nickname":"name-2111"
"create": "_id":"2104"
"id": "2104", "nickname":"name-2104"
3. bulk 之 update (批量更新)
POST: http://192.168.92.140:9200/shop2/_doc/_bulk
"update": "_id":"2111"
"doc":"nickname":"name-2211"
"update": "_id":"2104"
"doc": "id": "2114"
4. bulk 之 delete(批量删除)
POST: http://192.168.92.140:9200/shop2/_doc/_bulk
"delete": "_id":"2111"
"delete": "_id":"2104"
5. bulk 之 批量操作综合
POST: http://192.168.92.140:9200/shop2/_doc/_bulk
"delete": "_id":"2003"
"create": "_id": "20003"
"id":"20003","nickname":"name20003"
"update":"_id": "2002"
"doc":"id":"2222"
PS:
- 批量请求是会提交给内存的, 如果提交的请求过多, 则会导致性能的急剧下降.
- 最佳的批量总数是取决于电脑的硬件配置.
- 一个好的批量大小在开始处理的时候占用的物理内存大小约为5 - 15 MB.
以上是关于架构师成长记_第八周_19_ES- 批量操作 bulk的主要内容,如果未能解决你的问题,请参考以下文章