Javascript Elasticsearch JS-未定义变量[x]
在test Elasticsearch index中,我已经为文档编制了索引,现在我想通过将文档的Javascript Elasticsearch JS-未定义变量[x],javascript,elasticsearch,elasticsearch-6,Javascript,elasticsearch,Elasticsearch 6,在test Elasticsearch index中,我已经为文档编制了索引,现在我想通过将文档的length属性设置为100来更新文档。我想通过脚本(因为这是一个简单的例子来说明我的问题)通过包来实现这一点 但是,我收到以下错误: { "error": { "root_cause": [ { "type": "remote_transport_exception", "reason": "[6pAE96Q][127.0.0.1:9300]
length
属性设置为100
来更新文档。我想通过脚本(因为这是一个简单的例子来说明我的问题)通过包来实现这一点
但是,我收到以下错误:
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[6pAE96Q][127.0.0.1:9300][indices:data/write/update[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to execute script",
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"ctx._source.length = length",
" ^---- HERE"
],
"script": "ctx._source.length = length",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [length]is not defined."
}
}
},
"status": 400
}
即使我在body.params.length
中包含了length
属性,也会发生这种情况
使用以下命令:
- Elasticsearch服务器
v6.1.1
- Elasticsearch JavaScript客户端
v14.1.0
如何解决此问题?此处的文档错误 在他们的例子中,他们提出:
client.update({
index: 'myindex',
type: 'mytype',
id: '1',
body: {
script: 'ctx._source.tags += tag',
params: { tag: 'some new tag' }
}
}, function (error, response) {
// ...
});
实际上,body.script
应该是:
client.update({
index: 'myindex',
type: 'mytype',
id: '1',
body: {
script: {
lang: 'painless',
source: 'ctx._source.tags += params.tag',
params: { tag: 'some new tag' }
}
}
}, function (error, response) {
// ...
});
它应该有用
您可能需要参考该页面 client.update({ index: 'myindex', type: 'mytype', id: '1', body: { script: { lang: 'painless', source: 'ctx._source.tags += params.tag', params: { tag: 'some new tag' } } } }, function (error, response) { // ... });
script: {
lang: 'painless',
source: 'ctx._source.length = params.length',
params: { length: 100 }
}