-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
Elasticsearch version (bin/elasticsearch --version): 6.4.1
Plugins installed: []
JVM version (java -version): OpenJDK 64-bit Server VM 10.0.2
OS version (uname -a if on a Unix-like system): Linux 4.15.0-34-generic #37-Ubuntu SMP
Description of the problem including expected versus actual behavior:
If you (accidentally) include both a script and an update:doc action in a bulk update, it does not always return the appropriate error and can fail to execute a script silently.
Steps to reproduce:
Setup:
PUT /test
PUT /test/_doc/test
{ "message":"hello world" }
The expected behaviour - when both script and update:doc actions are used in this order:
POST _bulk
{"update":{"_index":"test","_type":"_doc","_id":"test"}}
{"script":{"source":"ctx._source.message = 'set by script'"},"update":{"doc":{"message":"set by update:doc"}}}
Elasticsearch correctly responds with the error:
{
"error": {
"root_cause": [
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: can't provide both script and doc;"
}
],
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: can't provide both script and doc;"
},
"status": 400
}
But if you switch the order putting update:doc first, then script:
POST _bulk
{"update":{"_index":"test","_type":"_doc","_id":"test"}}
{"update":{"doc":{"message":"set by update:doc"}},"script":{"source":"ctx._source.message = 'set by script'"}}
It returns successfully:
{
"took": 9,
"errors": false,
"items": [
{
"update": {
"_index": "test",
"_type": "_doc",
"_id": "test",
"_version": 5,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 4,
"_primary_term": 1,
"status": 200
}
}
]
}
But only the update has been done, and the script section has been silently ignored:
GET /test/_doc/test
{
"_index": "test",
"_type": "_doc",
"_id": "test",
"_version": 5,
"found": true,
"_source": {
"message": "set by update:doc"
}
}
It would be good to
- Fail consistently when both
update:docandscriptare provided regardless of order - Add explicit details to the documentation noting that only one action can be used per update