当前位置: 首页 > news >正文

ES DSL 常用修改语句

字段值替换修改

修改sql

update zyzkwjj set dh=replace(dh,"WS","WSS") where dh like '%WS%'
update zyzkwjj
set dh = replace(dh, 'WS', 'DZ'),ztm = replace(ztm, 'WS', 'DZ'),zrz = replace(zrz, 'WS', 'DZ')
where dh like '%WS%' or ztm like '%WS%' or zrz like '%WS%';

对应DSL语句

POST zyzkwjj/_update_by_query
{"script": {"source": "ctx._source.dh = ctx._source.dh.replace('WS', 'WSS')","lang": "painless"},"query": {"wildcard": {"dh": {"value": "*WS*"}}}
}

POST zyzkwjj/_update_by_query
{"script": {"source": """if (ctx._source.dh != null) {ctx._source.dh = ctx._source.dh.replace('WS', 'DZ');}if (ctx._source.ztm != null) {ctx._source.ztm = ctx._source.ztm.replace('WS', 'DZ');}if (ctx._source.zrz != null) {ctx._source.zrz = ctx._source.zrz.replace('WS', 'DZ');}""","lang": "painless"},"query": {"bool": {"should": [{"wildcard": {"dh": {"value": "*WS*"}}},{"wildcard": {"ztm": {"value": "*WS*"}}},{"wildcard": {"zrz": {"value": "*WS*"}}}]}}
}

字段值组合修改

修改SQL

update zyzkwjj set dh=concat(qzh,'-',daml,'-',lpad(nd,4,0),'-',bgqx,'-',lpad(jd,4,'0'))  where dh is null or length(dh)<=0

DSL语句

POST zyzkwjj/_update_by_query
{"script": {"source": """if (ctx._source.dh == null || ctx._source.dh.length() <= 0) {String nd = ctx._source.nd != null ? ctx._source.nd : '';String jd = ctx._source.jd != null ? ctx._source.jd : '';String formattedNd = nd.length() < 4 ? String.format('%04d', Integer.parseInt(nd)) : nd;String formattedJd = jd.length() < 4 ? String.format('%04d', Integer.parseInt(jd)) : jd;ctx._source.dh = ctx._source.qzh + '-' + ctx._source.daml + '-' + formattedNd + '-' + ctx._source.bgqx + '-' + formattedJd;}""","lang": "painless"},"query": {"bool": {"must": [{"bool": {"should": [{"bool": {"must_not": {"exists": {"field": "dh"}}}},{"script": {"script": "doc['dh'].length() <= 0"}}]}}]}}
}

根据ID修改值

修改SQL

update zyzkwjj set create_time=now(),admin_id='111' where id='1111'

DSL语句

POST zyzkwjj/_update/1111
{"doc": {"create_time": "now","admin_id": "111"}
}

不加条件修改 

POST zyzkwjj/_update_by_query
{"script": {"source": """ctx._source.create_time = 'now';ctx._source.admin_id = '111';""","lang": "painless"},"query": {"match_all": {}}
}


http://www.mrgr.cn/news/98557.html

相关文章:

  • 三、The C in C++
  • MyBatis持久层框架
  • uniapp的通用页面及组件基本封装
  • 基于Espressif-IDE的esp32开发
  • 第 2 篇:快速上手 Framer Motion(实操入门)
  • 从0到1构建企业级消息系统服务体系(一):产品架构视角下的高并发设计与动态响应能力建设
  • Asp.Net Core学习随笔
  • 【版本控制】git命令使用大全
  • netty-socketio + springboot 消息推送服务
  • 爬虫框架 - Coocan
  • JWT令牌:实现安全会话跟踪与登录认证的利器
  • 解决PIP 安装出错ERROR: cp310-cp310-manylinux_2_28_x86_64.whl is not a supported wheel
  • webpack vite
  • 半导体设备通信标准—secsgem v0.3.0版本使用说明文档(1)之概述、如何安装及使用方法
  • 【Bluedroid】A2DP Sink播放流程源码分析(二)
  • VGA显示
  • vue3环境搭建、nodejs22.x安装、yarn 1全局安装、npm切换yarn 1、yarn 1 切换npm
  • Jenkins插件下载慢解决办法
  • RAGFlow本地部署教程 :多模态检索+动态生成,用AI重构企业知识生产力
  • 第3篇:深入 Framer Motion Variants:掌握组件动画编排的艺术