elasticsearch - 如何使用无痛脚本将新字段添加到文档中
问题描述
如果不存在,有没有办法在无痛脚本中创建文档中的字段?
我正在使用类似的东西:
if(!ctx._source.tags.contains(....)
但文档中可能不存在标签字段
可以吗?
谢谢。
解决方案
如果您打算使用_update_by_query
API,我建议您执行以下操作:
POST your_index/_update_by_query
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "tags"
}
}
}
},
"script": {
"source": "ctx._source.tags = ''"
}
}
否则,只需使用无痛,您可以执行以下操作:
{
"script": {
"source": """
if(ctx._source.tags == null) {
ctx._source.tags = null;
}
"""
}
}
推荐阅读
- jquery - 使用 JQuery 在每个 Input Type="number" 中设置不同的计算
- ios - 无权从照片库中挑选照片
- javascript - 立即抓取mySql中自动生成的字段以供使用
- r - tbl_summary 和数值变量
- assembly - 返回到 Eip 寄存器中存储的指令之后的下一条指令
- c# - 使用 PuppeteerSharp 访问 windows.localStorage
- go - 我如何验证用户:在 golang 中传递代理
- python - 嵌套循环和 df.append 的问题
- ios - 使用 Geometry Reader 和 ScrollVIew 时,SwiftUI 视图向右偏移
- excel - 比较并显示两列的差异,然后也显示多列的差异