ElasticSearch-bulk批量操作增删改查(python实现)
bulk有哪些类型的操作可以执行呢?#1.bulk的语法是怎样的呢?每一个操作要两个json串语法如下{action:{metadata}}{data}#2.bulk的操作有以下几种 1delete删除一个文档只要1个json串就可以了 2createPUT/index/type/id/_create强制创建 3index普通的put操作可以是创建文档也可以是全量替换文档 4update执行的partial update操作tips:bulk api对json的语法有严格的要求每个json串不能换行只能放一行同时一个json串和一个json串之间必须有一个换行基于python实现批量增删改查操作fromelasticsearchimportElasticsearchfromelasticsearchimporthelpers esElasticsearch(hostsip:port)bulk_list[{_op_type:delete,_index:test_index,_type:test_type,_id:3,},{_op_type:create,_index:test_index,_type:test_type,_id:12,_source:{test_field:test12}},{_op_type:index,_index:test_index,_type:test_type,_id:2,_source:{test_field:replaced test2}},{_op_type:update,_index:test_index,_type:test_type,_id:1,_retry_on_conflict:3,doc:{test_field2:bulk test1}}]resulthelpers.bulk(es,bulk_list)print(result)# 返回结果如下,表示4条语句执行成功(4,[])基于kibana实现批量增删改查操作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}}{doc:{test_field2:bulk test1}}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}}{doc:{test_field2:bulk test1}}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}}{doc:{test_field2:bulk test1}} bulk操作中任意一个操作失败是不会影响其他的操作的但是在返回结果里会告诉你异常日志

相关新闻

数据中心液冷技术:高效散热与节能解决方案

数据中心液冷技术:高效散热与节能解决方案

1. 算力基建浪潮下的数据中心温控困局去年夏天,某大型互联网公司的数据中心因为空调系统故障导致服务器过热宕机,直接造成每小时数百万的经济损失。这个真实案例暴露出传统风冷技术在算力爆发式增长背景下的力不从心。随着AI训练、科学计算等高性能计算需…

2026/7/28 19:54:23 阅读更多
物联网安全:SE050安全元件与PIC18F87J50的硬件加密方案

物联网安全:SE050安全元件与PIC18F87J50的硬件加密方案

1. 物联网安全现状与SE050的定位在智能家居、工业4.0等场景中,设备身份伪造、数据篡改、中间人攻击等安全威胁日益突出。传统MCU方案通常依赖软件加密库,存在密钥泄露风险。恩智浦的EdgeLock SE050安全元件(Secure Element)正是为…

2026/7/28 19:54:23 阅读更多
封装mysql SDK

封装mysql SDK

/*测试代码 char**results; char**field new char*[4]; field[0] new char[64]; field[1] new char[64]; field[2] new char[64]; field[3] NULL; char*sn "sn_id"; char*name "name"; char*electricity "request_count"; strcpy_s(fiel…

2026/7/28 19:54:23 阅读更多
python爬取贝壳中二手房的数据

python爬取贝壳中二手房的数据

前言:通过代码爬取贝壳中二手房的数据,以此给更多需要了解爬虫或者二手房信息的人提供便利。 第一部分:爬取地址 1.1贝壳首页地址 jiujiang.ke.com 第二部分:爬取数据 2.1输入要爬多少页 int(input(输入一共要多少页&#xf…

2026/7/29 4:26:03 阅读更多
学习日记 7.28

学习日记 7.28

在机器学习的学习之路上,线性回归和逻辑回归是两块重要的基石。今天我们将通过两个实战案例,从理论到代码,全面掌握这两种算法的应用:案例一:多元线性回归 —— 根据体重和年龄预测血压收缩压;案例二&#…

2026/7/29 4:26:03 阅读更多
嵌入式设备与云端安全连接方案及优化技巧

嵌入式设备与云端安全连接方案及优化技巧

1. 项目背景与硬件选型解析当我们需要在嵌入式设备与云端建立安全连接时,硬件平台的选择直接影响着整个系统的性能和可靠性。这个项目中选用的A5000显卡和TM4C123GH6PZ微控制器组合,恰好覆盖了从边缘计算到云端协同的全链路需求。NVIDIA RTX A5000作为专…

2026/7/29 4:16:02 阅读更多