-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
Elasticsearch version (bin/elasticsearch --version): 6.x
When a user adds a watch in 5.x, that contains a script and the script section contains a lang field, the watch will be broken after upgrading to 6.x. The original PR adding this check was done in #25610
Reproduction
Have a 5.x node where you add this script and this watch (or just index via bulk under 6.x as shown as well).
POST _scripts/my_script
{
"script": {
"lang": "painless",
"source": "return true"
}
}
# add under 5.x
PUT _xpack/watcher/watch/my_watch
{
"trigger": {
"schedule": {
"interval": "10h"
}
},
"input": {
"simple": {
"foo": "bar"
}
},
"condition": {
"script": {
"id": "my_script",
"lang": "painless"
}
},
"actions": {
"logme": {
"logging": {
"text": "{{ctx}}"
}
}
}
}
# or emulate under 6.x
POST _xpack/watcher/_stop
PUT _bulk
{"index":{"_index":".watches","_type":"doc","_id":"my_watch"}}
{"trigger":{"schedule":{"interval":"10h"}},"input":{"simple":{"foo":"bar"}},"condition":{"script":{"id":"my_script","lang":"painless"}},"actions":{"logme":{"logging":{"text":"{{ctx}}"}}}}
POST _xpack/watcher/_start
# this is gonna fail
GET _xpack/watcher/watch/my_watch
with the following exception
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "illegally specified <lang> for a stored script"
}
],
"type": "illegal_argument_exception",
"reason": "illegally specified <lang> for a stored script"
},
"status": 400
}
If you store the above watch in 5.x you will get a depreciation message though.
Discuss: Would it make sense to check for the lang field in the condition, the transform and the conditions and transforms in the action, and optionally remove the lang field as part of the reindex that is done when running the upgrade API?
This will not catch all the possible cases, but I think 99%.