Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Elasticsearch JS-未定义变量[x]_Javascript_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Elasticsearch 6 - Fatal编程技术网 elasticsearch,elasticsearch-6,Javascript,elasticsearch,Elasticsearch 6" /> elasticsearch,elasticsearch-6,Javascript,elasticsearch,Elasticsearch 6" />

Javascript Elasticsearch JS-未定义变量[x]

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]

在test Elasticsearch index中,我已经为文档编制了索引,现在我想通过将文档的
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 }
}