首页 > 其他分享 >27_分布式文档系统_上机动手实战演练bulk批量增删改

27_分布式文档系统_上机动手实战演练bulk批量增删改

时间:2024-10-01 19:46:13浏览次数:1  
标签:index 27 bulk test version 增删 type id

课程大纲

1、bulk语法

POST /_bulk
{ "delete": { "_index": "test_index", "_type": "test_type", "_id": "3" }}
{ "create": { "_index": "test_index", "_type": "test_type", "_id": "12" }}
{ "test_field": "test12" }
{ "index": { "_index": "test_index", "_type": "test_type", "_id": "2" }}
{ "test_field": "replaced test2" }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} }

每一个操作要两个json串,语法如下:

{"action": {"metadata"}}

举例,比如你现在要创建一个文档,放bulk里面,看起来会是这样子的:

{"index": {"_index": "test_index", "_type", "test_type", "_id": "1"}}

有哪些类型的操作可以执行呢?
(1)delete:删除一个文档,只要1个json串就可以了
(2)create:PUT /index/type/id/_create,强制创建
(3)index:普通的put操作,可以是创建文档,也可以是全量替换文档
(4)update:执行的partial update操作

bulk api对json的语法,有严格的要求,每个json串不能换行,只能放一行,同时一个json串和一个json串之间,必须有一个换行

{
"error": {
"root_cause": [
{
"type": "json_e_o_f_exception",
"reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5a5932cd; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5a5932cd; line: 1, column: 3]"
}
],
"type": "json_e_o_f_exception",
"reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5a5932cd; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5a5932cd; line: 1, column: 3]"
},
"status": 500
}

{
"took": 41,
"errors": true,
"items": [
{
"delete": {
"found": true,
"_index": "test_index",
"_type": "test_type",
"_id": "10",
"_version": 3,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 200
}
},
{
"create": {
"_index": "test_index",
"_type": "test_type",
"_id": "3",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true,
"status": 201
}
},
{
"create": {
"_index": "test_index",
"_type": "test_type",
"_id": "2",
"status": 409,
"error": {
"type": "version_conflict_engine_exception",
"reason": "[test_type][2]: version conflict, document already exists (current version [1])",
"index_uuid": "6m0G7yx7R1KECWWGnfH1sw",
"shard": "2",
"index": "test_index"
}
}
},
{
"index": {
"_index": "test_index",
"_type": "test_type",
"_id": "4",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true,
"status": 201
}
},
{
"index": {
"_index": "test_index",
"_type": "test_type",
"_id": "2",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": false,
"status": 200
}
},
{
"update": {
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_version": 3,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 200
}
}
]
}

bulk操作中,任意一个操作失败,是不会影响其他的操作的,但是在返回结果里,会告诉你异常日志

POST /test_index/_bulk
{ "delete": { "_type": "test_type", "_id": "3" }}
{ "create": { "_type": "test_type", "_id": "12" }}
{ "test_field": "test12" }
{ "index": { "_type": "test_type" }}
{ "test_field": "auto-generate id test" }
{ "index": { "_type": "test_type", "_id": "2" }}
{ "test_field": "replaced test2" }
{ "update": { "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} }

POST /test_index/test_type/_bulk
{ "delete": { "_id": "3" }}
{ "create": { "_id": "12" }}
{ "test_field": "test12" }
{ "index": { }}
{ "test_field": "auto-generate id test" }
{ "index": { "_id": "2" }}
{ "test_field": "replaced test2" }
{ "update": { "_id": "1", "_retry_on_conflict" : 3} }

2、bulk size最佳大小

bulk request会加载到内存里,如果太大的话,性能反而会下降,因此需要反复尝试一个最佳的bulk size。一般从10005000条数据开始,尝试逐渐增加。另外,如果看大小的话,最好是在515MB之间。

标签:index,27,bulk,test,version,增删,type,id
From: https://www.cnblogs.com/siben/p/18443149

相关文章

  • 33_分布式文档系统_bulk api的奇特json格式与底层性能优化关系大揭秘
    课程大纲bulkapi奇特的json格式{"action":{"meta"}}\n{"data"}\n{"action":{"meta"}}\n{"data"}\n[{"action":{},"data":{}}]1、bulk中的每个操作都可能要转发到不同的node的shard去执行2、如果采用比较良好的......
  • MySQL 的增删改查
    MySQL的增删改查1.CRUD注释:在SQL中可以使用“--空格+描述”来表示注释说明CRUD即增加(Create)、查询(Retrieve)、更新(Update)、删除(Delete)四个单词的首字母缩写。createtablestudent(idint,namevarchar(20));1.1新增语法:insert[into]table_name[column]v......
  • jsphealth59p27(程序+源码+数据库+调试部署+开发环境
    本系统(程序+源码+数据库+调试部署+开发)环境带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容一、课题背景随着生活节奏的加快和社会压力的增加,健康问题日益成为人们关注的焦点。无论是学校、社会还是家庭,都越来越重视身体健康,定期体检已成为......
  • Connector C++ 连接 MySQL 数据库之增删改查
    在vcpkg中折腾了mysql-connector-cpp8.0很久,一直连接不上远程数据库,后面查官方文档,mysql-connector-cpp8.0好像只支持MySQL8.0以上的数据库,本来想把远程服务器上的MySQL升级到MySQL8.0,后面发现测试服务器的配置有点拉跨,架不住MySQL8.0,但是vcpkg中又没有mysql-c......
  • 数组中洛谷p1427小鱼的数字游戏
    先来看看题目吧:然后先来复习一下数组:你需要了解:数组的定义,数组的创建,数组的初始化,数组的使用(尤其是数组下标是从零开始的!)然后就来看思路吧:......
  • [1227]基于JAVA的宾馆房间智慧管理系统的设计与实现
    毕业设计(论文)开题报告表姓名学院专业班级题目基于JAVA的宾馆房间智慧管理系统的设计与实现指导老师(一)选题的背景和意义开题报告背景与意义:在当今信息化、智能化的时代背景下,宾馆服务业作为旅游业的重要组成部分以及城市商务活动的基础设施,其管理水平和服务质量直接影......
  • 小程序原生-利用setData()对不同类型的数据进行增删改
    1.声明和绑定数据wxml文件<view>{{school}}</view><view>{{obj.name}}</view><viewid="{{id}}">绑定属性值</view><checkboxchecked="{{isChecked}}"/><!--算数运算--><view>{{id+1}}</view&g......
  • nodejs koa 用knex.js链接mysql数据库,进行数据增删改查
    1、knex.js安装npminstallknex官方Installation|Knex.js中文文档|Knex.js中文网2、进行数据库链接constknex=require('knex')({client:'mysql2',connection:{host:'127.0.0.1',//地址user:'root',//账号......
  • STranslate(翻译、OCR工具) v1.2.5.927 绿色版
    ​ STranslate(翻译、OCR工具)v1.2.5.927绿色版下载地址:https://pan.quark.cn/s/1198dc1529f9介绍STranslate是一款为Windows用户设计的免费开源的翻译和OCR(光学字符识别)工具。它提供了一种高效且直观的方式来翻译和识别屏幕上的文字。该软件以「即开即用、即用即......
  • 9.27
    .创建数据库,1 主要数据表说明1.生产批次表 production_batch字段名类型Null默认描述BatchIDint否自增长主键生产批次IDProductIDint是 关联的产品IDBatchNumbervarchar(255)是 批次编号StartDate......