elasticsearch - 如何在 logstash 中使用脚本 upsert 来更新文档
问题描述
我正在使用下面的输出块来更新文档并为具有匹配 ID 的现有文档增加计数器(部分更新)。
目前,将第一个文档条目发布到 elasticsearch 中,“脚本”对后续更新调用没有影响。它没有增加计数器值
下面是使用 upsert 和脚本的 logstash 的输出块:
`output {
stdout { }
elasticsearch {
hosts => "localhost"
index => "test_dest"
script => "ctx._source.views+=1"
script_lang => "painless"
script_type => "inline"
# scripted_upsert => true
doc_as_upsert => true
document_id => "%{[userId]}"
}
stdout {
codec => "json"
}
}`
解决方案
尝试将其设置action
为“更新”和“真”scripted_upsert
,如下所示:
output {
elasticsearch {
action => "update"
hosts => "localhost"
index => "test_dest"
script => "ctx._source.views+=1"
script_lang => "painless"
script_type => "inline"
scripted_upsert => true
document_id => "%{[userId]}"
}
}
推荐阅读
- python - 站点可以通过其他站点上的 iframe 检测机器人吗?
- python - 我如何将 kepler.gl 与 Django 后端一起使用
- python - 无法在 VS 代码中读取文本文件(Python)
- jquery - jQuery:在父级中选择具有类名的内部和外部第一个元素
- angular - 角度测试 routerLinkActive 不起作用
- java - 您如何检测是否显示此弹出窗口
- java - 在 Springboot 中使用本机查询从 Postgres 数据库中获取数据很慢
- haskell - 在 GHC 的堆分析器文件中显示全名
- node.js - 使用 Node.js 服务器在 React 应用程序上隐藏 Google Maps JavaScript API 密钥值得吗?
- javascript - 在 React JS 中以编程方式第一次打开时,如何清除 Web 应用程序浏览器的缓存、cookie、本地存储等?