Scripting changes

edit

Scripting syntax

edit

The syntax for scripts has been made consistent across all APIs. The accepted format is as follows:

Inline/Dynamic scripts
"script": {
  "inline": "doc['foo'].value + val", 
  "lang":   "groovy", 
  "params": { "val": 3 } 
}

The inline script to execute.

The optional language of the script.

Any named parameters.

Indexed scripts
"script": {
  "id":     "my_script_id", 
  "lang":   "groovy", 
  "params": { "val": 3 } 
}

The ID of the indexed script.

The optional language of the script.

Any named parameters.

File scripts
"script": {
  "file":   "my_file", 
  "lang":   "groovy", 
  "params": { "val": 3 } 
}

The filename of the script, without the .lang suffix.

The optional language of the script.

Any named parameters.

For example, an update request might look like this:

POST my_index/my_type/1/_update
{
  "script": {
    "inline": "ctx._source.count += val",
    "params": { "val": 3 }
  },
  "upsert": {
    "count": 0
  }
}

A short syntax exists for running inline scripts in the default scripting language without any parameters:

GET _search
{
  "script_fields": {
    "concat_fields": {
      "script": "doc['one'].value + ' ' + doc['two'].value"
    }
  }
}

Scripting settings

edit

The script.disable_dynamic node setting has been replaced by fine-grained script settings described in Scripting settings.

Groovy scripts sandbox

edit

The Groovy sandbox and related settings have been removed. Groovy is now a non-sandboxed scripting language, without any option to turn the sandbox on.

Plugins making use of scripts

edit

Plugins that make use of scripts must register their own script context through ScriptModule. Script contexts can be used as part of fine-grained settings to enable/disable scripts selectively.