My goals -
- Find the existing field if present
(responseBody.results[i].statusCode)and copy it's value into a new field(embedded_error_code )at runtime - My original field is a list of array. Below is the structure of my original field -
(responseBody.results[i].statusCode)
"responseBody": {
"results": [
{
"hasErrors": false,
"statusCode": 201,
"uniqueId": "***",
"messageId": null,
"customerId": "***",
"developerMessage": "SUCCESS",
"userMessage": "SUCCESS",
"errors": []
}
]
},
My working Script when used with _update_by_query
POST _scripts/test-embedded-script
{
"script": {
"lang" : "painless",
"source": """
if(ctx._source.responseBody != null )
{
for (int i = 0; i < ctx._source.responseBody.results.length; ++i)
{
ctx._source.embedded_error_code = ctx._source.responseBody.results[i].statusCode;
}
}"""
}
}
My defined pipeline -
PUT _ingest/pipeline/apiproxy-embedded
{
"processors": [
{
"script": {
"id": "test-embedded-script"
}
}
]
}
I want to run the above script runtime, that's why I'm using Injest Pipeline
test-embedded-script isn't working in apiproxy-embedded pipeline.
Please help me to write this script as one of the processors of my pipeline.
NOTE : I'm not mapping/indexing my original field i.e. responseBody.results[i].statusCode and I don't want to map this field as well because it's of no use. I want to map new field only i.e. embedded_error_code.