Since String.format()
is not in the whitelist, sometimes it's nice to be able
to use string interpretation in scripts. Groovy allows doing this with GString
interpretation.
DELETE /script
{}
POST /script
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"doc": {
"properties": {
"body": {"type": "string"}
}
}
}
}
{"acknowledged":true}
{"acknowledged":true}
POST /script/doc/1?refresh
{"body": "foo"}
POST /script/doc/1/_update
{
"script": "ctx._source.body = ctx._source.body + \"${bar}\"",
"params": {
"bar": " hi"
}
}
GET /script/doc/1?_source=body
{}
{"_index":"script","_type":"doc","_id":"1","_version":1,"created":true}
{"_index":"script","_type":"doc","_id":"1","_version":2}
{"_index":"script","_type":"doc","_id":"1","_version":2,"found":true,"_source":{"body":"foo hi"}}