Jennifer Jennifer - 17 days ago 19
Groovy Question

How can i enable dynamic scripting in AWS ES?

I am using aws elastic service and indexed 650 000 data.
I need to add two new fields to the already indexed documents.
When I tried to call the updateByQuery function got the error, 'scripts of type [inline], operation [update] and lang [groovy] are disabled'.
I have fixed it by adding

script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.update: on on elasticsearch.yml and it works perfectly on local .
How can I add this configuration on aws es ?
I am getting the same error when I am updating documents in aws elastic service.

Here is my code. I want to update all records ( where "device"= deviceVal) by adding new fields Site and Time.

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)
});

Val Val
Answer

Building on the other answer where we use logstash to reindex into an AWS ES cluster, you simply need to add one more transformation where # add other transformations here is mentioned.

In your case the input part needs to contain a query for the device:

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

And the filter part would boil down to this, i.e. we rename the @timestamp field and add the Site field:

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