Elasticsearch批量操作bulk

Elasticsearch批量操作bulk

1.bulk请求体格式(不可以美化展示)
{action:{metadata }}\n
{request body }\n
{action: {netadata }}\n
{request body }\n
……
例如:
{“delete”: {“_index”:”library”,”_type”:”books”,”_id”:”1”}}

action(行为) | 解释
create |当文档不存在是创建之
index |创建新文档或替换已有文档
update |局部更新文档
delete |删除一个文档

#多重模式
#批量操作 _bulk 

POST /library/books/_bulk
{"index": {"_id":1}}
{"title": "Elasticsearch:The Definitive Guide","price":5}
{"index": {"_id":2}}
{"title": "The Elasticsearch cookbook","price":6}
{"index": {"_id":3}}
{"title": "Elasticsearch Blueprinnts","price":7}
{"index": {"_id":4}}
{"title": "Thinking in Python","price":8}
{"index": {"_id":5}}
{"title": "Thinking in Java","price":9}

GET /library/
GET /library/books/_mget
{
  "ids": ["1","2","3","4","5"]
}

# delete操作 和 update操作
# zhuyi注意delete下面没有具体的repuest body

POST /library/books/_bulk
{"delete": {"_index": "library", "_type": "books", "_id":"1"}}
{"create": "_index": "music", "_type": "classical", "_id":"1"}}
{"title":"Ave Verum Corpus"}
{"index": {"_index": "music", "_type": "classical"}}
{"title":"Litaniac de Veneravili Altaris Sacromento"}
{"update":{"_index": "library", "_type": "books", "_id":"2"}}
{"doc": {"price":"18"}}

GET /library/books/1
GET /library/books/_mget
{
  "ids":["1","2","3","4","5"]
}

_bulk是为了实现多个文档的create/index/update或者delete。

_bulk处理文档大小的最佳值:
数据加载在每个节点里的RAM里
请求的数据超过一定的大小,那bulk的处理性能就会降低
文档数据大小跟硬件配置,文档复杂度,以及当前集群的负载密切相关

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值