Description
If a bulk request contains any script error, Opensearch server points to
what is wrong with the request. This information is valuable to those
debug what is going on under the hood.
This PR adds missing bulk indexer response item fields.
Reproducer script
#!/bin/bash
INDEX="test"
OSURL="http://localhost:9200"
curl -X POST "$OSURL/$INDEX/_bulk?pretty&refresh=true" -H 'Content-Type: application/json' -d '
{"update":{"_id":"1","_index":"test"}}
{"script":{"source":"ctx._source.x = params.x","params":{"x":2}},"upsert":{"x":"1"}}
'
# null pointer exception: ctx._source.y
curl -X POST "$OSURL/$INDEX/_bulk?pretty&refresh=true" -H 'Content-Type: application/json' -d '
{"update":{"_id":"1","_index":"test"}}
{"script":{"source":"if (ctx._source.y < params.x) {ctx._source.y = params.x}","params":{"x": 2}},"upsert":{"x":"1"}}
'
Opensearch response
{
"took" : 287,
"errors" : false,
"items" : [
{
"update" : {
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"forced_refresh" : true,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
}
]
}
{
"took" : 3,
"errors" : true,
"items" : [
{
"update" : {
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"status" : 400,
"error" : {
"type" : "illegal_argument_exception",
"reason" : "failed to execute script",
"caused_by" : {
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"if (ctx._source.y < params.x) {",
" ^---- HERE"
],
"script" : "if (ctx._source.y < params.x) {ctx._source.y = params.x}",
"lang" : "painless",
"position" : {
"offset" : 26,
"start" : 0,
"end" : 31
},
"caused_by" : {
"type" : "null_pointer_exception",
"reason" : null
}
}
}
}
}
]
}
Check List
- [x] Commits are signed per the DCO using --signoff
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.