0

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.

vincent chou
  • 91
  • 2
  • 8
  • Is your file actually called "removeOperationField" or "removeOperationField.groovy" or something ? – sksamuel Jun 25 '15 at 09:42
  • file name is removeOperationField, since its type is groovy we don't have to declare lang. – vincent chou Jun 25 '15 at 09:46
  • java client can do this by `client.prepareUpdate("index", "type", "id") .setScript("removeIpField", ScriptService.ScriptType.FILE) .get ` – vincent chou Jun 25 '15 at 10:04
  • Yep I know you don't need to declare the language, but just wanted to make sure you hadn't given the file a file extension when you saved it. – sksamuel Jun 25 '15 at 10:12
  • full file name is "removeOperationField.groovy", file extension doesn't matter(I tried this). – vincent chou Jun 26 '15 at 02:36

1 Answers1

0

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)
  }
}
sksamuel
  • 16,154
  • 8
  • 60
  • 108
  • After upgraded to elastic4s 1.6.0, I finally saw this function. I was using 1.3.3 where script(string) cannot specify script type. – vincent chou Jun 26 '15 at 02:35