amazon-web-services - 如何在 AWS ES 中启用动态脚本?

标签 amazon-web-services elasticsearch groovy

我正在使用 aws 弹性服务并索引了 650 000 个数据。 我需要向已索引的文档添加两个新字段。 当我尝试调用 updateByQuery 函数时出现错误,“类型 [inline]、操作 [update] 和 lang [groovy] 的脚本被禁用”。 我已经通过添加修复了它
script.engine.groovy.inline.aggs:开启 script.engine.groovy.inline.update:在elasticsearch.yml上,它在本地完美运行。 如何在 aws es 上添加此配置? 当我更新 aws elastic 服务中的文档时,我遇到了同样的错误。

这是我的代码。我想通过添加新字段“站点”和“时间”来更新所有记录(其中“device”= deviceVal)。

var site = 'some value';
var deviceVal = '123'; 

var theScript = {
    "inline": "ctx._source.Site = '"+ site + "';ctx._source.Time = '"+ new Date().getTime() + "'"
}   
var match = {
    "match": { "device": deviceVal }
}

client.updateByQuery({
    index: 'my_index',
    type:'txt',

    "body": {
        "query": match, 
        "script":theScript
    }

}, function (error, response) {
    // console.log("success")
    console.log('error--',error)
    console.log('response--',response)
});

最佳答案

构建于 the other answer当我们使用 Logstash 重新索引到 AWS ES 集群时,您只需要再添加一个转换,其中提到了# add other conversions

在您的情况下,输入部分需要包含设备的查询:

input {
  elasticsearch {
   hosts => ["my-elasticsearch-domain.us-west-2.es.amazonaws.com:80"]
   index => "my_index"
   query => '{"query": {"match":{"device": "123"}}}'
   docinfo => true
  }
}

过滤器部分将归结为这一点,即我们重命名 @timestamp 字段并添加 Site 字段:

filter {
 mutate {
  remove_field => [ "@version" ]
  rename => { "@timestamp" => "Time" }
  add_field => { "Site" => "some value" }
 }
}

关于amazon-web-services - 如何在 AWS ES 中启用动态脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40766848/

相关文章:

amazon-web-services - 克隆 aws 环境,使其共享相同的 RDS 数据库

node.js - 当我的 API 出现故障时,如何收到电子邮件?

intellij-idea - 无法从 IntelliJ 中的 Gradle 脚本解决 groovy 文件

grails - 如何在gsp中显示域值

amazon-web-services - 构建后自动将静态网站文件部署到 S3

amazon-web-services - Assets 执行步骤在代码管道中失败 - CDK (Java)

elasticsearch - Elasticsearch 7无法创建索引

Mysql InnoDB表到elasticsearch : ON UPDATE CURRENT TIMESTAMP inside transaction

mysql - 将Mysql查询转换为Elastic Search

grails - 哪个SDK可将现有Grails项目导入IntelliJ IDE?