我正在使用下面的代码来更新 elasticsearch 中的文档
client.update({
index: 'myindex',
type: 'mytype',
id: '1',
body: {
script: 'ctx._source.tags += tag',
params: { tag: 'some new tag' }
}
}, function (error, response) {
});
但是,这会引发编译错误。当我用上面的 params.tag
替换标签时,它将 null 附加到当前字段,即将 params.tag
标识为 null
。
最佳答案
我遇到过类似的困惑。 This document分享您在问题中的示例。另一方面,this document分享一个不同的例子(我开始工作)。
你的更新语句应该是这样的:
client.update({
index: 'myindex',
type: 'mytype',
id: '1',
body: {
script: {
inline: 'ctx._source.tags.add(params.tag)',
lang: 'painless',
params: {
tag: 'some new tag'
}
}
}
}, function (error, response) {
// handling of error/response
});
** 注意 .add
而不是 +=
添加到数组时的情况。
关于node.js - 脚本化动态更新在 ElasticSearch 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41698689/