elasticsearch - Elasticsearch 批量更新查询?
问题描述
在这里阅读本文后,我无法将以下 SQL 转换为弹性 dsl:
UPDATE myIndex
set field1 = staticValue1, field2 = staticValue2
Where {
"query": {
"bool": {
"must_not": {
"exists": {
"field": "cnpj_estabelecimento"
}}}}}
我怎样才能做到这一点?
解决方案
使用Update By Query API时,您有两个部分:
询问。将更新哪些元素。
脚本。会做哪些改变。
对于脚本部分,您将不得不玩一点Painless。不要相信这个名字:学习无痛是痛苦的(一开始)。
现在,对于您的特定情况,您想要做的事情应该如下所示:
POST /myIndex
"query" : {
"bool" : {
"must_not" : {
"exists" : {
{
"field": "cnpj_estabelecimento"
}
}
}
}
},
"script" : {
"inline" : "ctx._source.field1= 'staticValue1'; ctx._source.field2= staticValue2;",
"lang" : "painless"
}
}
请注意,当您调用 Update By Query API 时,您是通过 POST 而不是 UPDATE 进行的。
希望这有帮助!:D
推荐阅读
- spring-boot - Stackdriver - 所有日志都映射为 INFO
- powershell - 根据扩展名的情况寻找删除目录中文件的方法
- android - SetSelected 在相对布局中的 5 个按钮之间
- java - 生成构造函数
- github - 将数据从 TFS 传输到 GitHub
- android - 如何在真正的手机上运行应用程序而不是使用模拟器?
- r - 如何为随机森林建立 k 折交叉验证
- javascript - Promise 是一种实现异步编程的技术吗?
- wordpress - wordpress domine 映射 subdomine noindex htaccess robots.txt
- php - 当我使用 Kartik Editable Widget 时出现错误 - Uncaught TypeError: elem.replace is not a function