update with script pre-installed in elasticsearch

206 views Asked by At

I want to use scripts in the way[ https://www.elastic.co/blog/running-groovy-scripts-without-dynamic-scripting ] for security purpose.

I tried this in sense(chrome plugin) and it works well. Wondering how to achieve this in elastic4s.

For example, I want to remove a field from doc, and code like this:

def replaceWithId(alarmId: String, fieldName: String, fieldValue: Map[String, Any]) = {
client.execute {
  update id alarmId in IndexType script """{"file":"removeOperationField"}"""

}}

but it failed.

1

There are 1 answers

1
sksamuel On BEST ANSWER

You need to set the script type, rather than including it in the json explicitly, eg:

def replaceWithId(alarmId: String) = {
  client.execute {
    update id alarmId in IndexType script("scriptname", ScriptType.File)
  }
}