ES:使用painless脚本修改字段内容

复制代码
假设index-a的url字段包含内容“..\..\a\b”,现在要把它替换为空
bash 复制代码
curl -u "elastic:elastic" -k "https://localhost:9200/index-a/_update_by_query" \
-H 'Content-Type: application/json' \
-d'
{
  "script": {
    "source": "ctx._source.url = ctx._source.url.replace(\"..\\\\..\\\\a\\\\b\\\\\", \"\")",
    "lang": "painless"
  }
}
'

解释

  • -k--insecure:允许 curl 忽略 SSL 证书验证(适用于自签名证书)。

  • -u:提供用户名和密码进行基本认证。

  • -X POST:指定 HTTP 方法为 POST。

  • -H 'Content-Type: application/json':指定请求的内容类型为 JSON。

  • -d:发送请求体数据。需要注意里面对"\"的转义

在请求体中:

  • script:指定要执行的脚本。

  • source:脚本内容,使用 Painless 脚本语言。

  • lang:指定脚本语言为 Painless。

相关推荐
okiseethenwhat4 分钟前
Java 进程 CPU 飙高排查全流程详解
java·开发语言
2601_949816685 分钟前
使用rustDesk搭建私有远程桌面
java
看见代码就想敲12 分钟前
java学习之(Maven pom.xml 详细讲解)
java·学习·maven
糖炒栗子032621 分钟前
图片加水印与 EXIF 保留方案
java
tongxh42321 分钟前
Spring Boot问题总结
java·spring boot·后端
Chan1627 分钟前
SpringAI:RAG 最佳实践与调优
java·spring boot·ai·java-ee·intellij-idea·rag·springai
odng28 分钟前
Windsurf / Codex 默认只显示 3 个最近任务,如何改成 100 个
java
m0_7167652329 分钟前
C++巩固案例--通讯录管理系统详解
java·开发语言·c++·经验分享·学习·青少年编程·visual studio
Predestination王瀞潞30 分钟前
Java EE3-我独自整合(第三章:Spring DI 入门案例)
java·spring·java-ee
Ttang2333 分钟前
Java爬虫:Jsoup+OkHttp实战指南
java·爬虫·okhttp