ElasticSearch7.3学习(三)----采用restful风格 批量(bulk)增删改
2023-03-14 09:43:51 时间
Bulk 操作是将文档的增删改查一些列操作,通过一次请求全都做完。目的是减少网络传输次数。
语法:
POST /_bulk {"action": {"metadata"}} {"data"}
如下操作,创建14,创建5,删除5,更新14
POST /_bulk { "create": { "_index": "test_index", "_id": "14" }} { "test_field": "test14" } { "create": { "_index": "test_index", "_id": "5" }} { "test_field": "test14" } { "delete": { "_index": "test_index", "_id": "5" }} { "update": { "_index": "test_index", "_id": "14"} } { "doc" : {"test_field" : "bulk test"} }
结果
{ "took" : 1520, "errors" : false, "items" : [ { "create" : { "_index" : "test_index", "_type" : "_doc", "_id" : "14", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1, "status" : 201 } }, { "create" : { "_index" : "test_index", "_type" : "_doc", "_id" : "5", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 1, "_primary_term" : 1, "status" : 201 } }, { "delete" : { "_index" : "test_index", "_type" : "_doc", "_id" : "5", "_version" : 2, "result" : "deleted", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 2, "_primary_term" : 1, "status" : 200 } }, { "update" : { "_index" : "test_index", "_type" : "_doc", "_id" : "14", "_version" : 2, "result" : "updated", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 3, "_primary_term" : 1, "status" : 200 } } ] }
总结:
为啥不采用Java里面传统的Json对象去实现批量操作,原因为解析Json字符串的时候,会保留一个比较大的Json对象放在Java内存中,大数据量的时候明显不可取。因此按照普通字符串读取就OK了。
1. 功能:
- delete:删除一个文档,只要1个json串就可以了
- create:相当于强制创建 PUT /index/type/id/_create
- index:普通的put操作,可以是创建文档,也可以是全量替换文档
- update:执行的是局部更新partial update操作
2. 格式:每个json不能换行。相邻json必须换行。
3. 隔离:每个操作互不影响。操作失败的行会返回其失败信息。
4. 实际用法:bulk请求一次不要太大,否则一下积压到内存中,性能会下降。所以,一次请求几千个操作、大小在几M正好。
相关文章
- 【Java】Java学习笔记之二----修饰符
- 新的 AWS 奖学金计划帮助代表性不足和服务不足的学生为 AI 和 ML 领域的职业做好准备
- 现已推出预览版 — Amazon SageMaker Studio Lab,一项具有机器学习 (ML) 功能的免费学习和实验服务
- 基于云原生构建的 HPC 平台演示
- 构建 ElastiCache for Redis 慢日志可视化平台
- 智能家居物联网平台之-设备状态管理
- 使用 Deep Learning AMI 快速实现 CUDA,cuDNN 和深度学习框架版本兼容
- 智能家居物联网平台之 —— 模组配网
- 利用Amazon EC2进一步降低DeepRacer训练成本
- 使用机器学习和 AWS Inferentia 扩缩广告验证
- 使用Amazon Web Services CDK,在云上构建DataOPS 平台
- 在Amazon EKS上部署Zeppelin和Spark分析平台
- 通过 SageMaker 与 Step Functions 实现机器学习的 CI/CD 方案
- 基于AWS machine learning bot 的 named-entity recognition (NER) 快速解决方案
- 【java8】java新特性(一)——全局观
- 介绍最新的 AWS 勇士 – 2021 年 6 月
- 零代码实现基于机器学习的游戏运营优化
- Amazon SageMaker使用数十亿条参数简化深度学习模型训练
- AWS DeepRacer League’s 2021 年赛季推出新的公开和专业赛组
- 使用Amazon SageMaker将基于机器学习的实时洞见分析引入英式橄榄球运动