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。

相关推荐
鶴哥只手遮天1 分钟前
Spring Boot 4.1.1 深度源码解析-第 28 章 AOT 与 GraalVM Native与序列化模型
java·后端·开源
鶴哥只手遮天1 分钟前
Spring Boot 4.1.1 深度源码解析-第 27 章 · 可执行归档与 Loader:`JarLauncher` 与嵌套 jar
java·后端·开源
鶴哥只手遮天1 分钟前
Spring Boot 4.1.1 深度源码解析-第 25 章 · Actuator 与健康:端点机制、`HealthIndicator`、管理端口子上下文
java·后端·开源
鶴哥只手遮天2 分钟前
Spring Boot 4.1.1 深度源码解析-第 16 章 · 排序、元数据与报告:`AutoConfigurationSorter`、配置元数据、条件报告
java·后端·开源
鶴哥只手遮天3 分钟前
Spring Boot 4.1.1 深度源码解析-第 14 章 · 自动配置引擎:`AutoConfigurationImportSelector` 全流程
java·后端·开源
鶴哥只手遮天4 分钟前
Spring Boot 4.1.1 深度源码解析-第 24 章 · 日志系统:`LoggingApplicationListener` 与结构化日志
java·后端·开源
鶴哥只手遮天5 分钟前
Spring Boot 4.1.1 深度源码解析-第 22 章 · 数据源、连接池与事务
java·后端·开源
鶴哥只手遮天6 分钟前
Spring Boot 4.1.1 深度源码解析-第 17 章 应用类型推断与上下文工厂:`WebApplicationType`
java·后端·开源
鶴哥只手遮天6 分钟前
Spring Boot 4.1.1 深度源码解析-第 23 章 · JPA / Hibernate 与持久化模块
java·后端·开源
鶴哥只手遮天7 分钟前
Spring Boot 4.1.1 深度源码解析-第 12 章 · 事件总线与 Bootstrap 上下文
java·后端·开源