Hello Everyone:
I am using Elasticsearch 7.8 version.
I have a mutliple conditions to be checked using set processor ...
I am using below code
curl -X POST "localhost:9200/_ingest/pipeline/_simulate?pretty" -H 'Content-Type: application/json' -d'
{
"docs": [
{ "_source" : { "outer": {"inner": "X"} } },
{ "_source" : { "outer": {"inner": "Y"} } },
{ "_source" : { "outer": {"inner": "Z"} } },
{ "_source" : { "outer": {"inner": "T"} } }
],
"pipeline": {
"processors": [
{
"set": {
"if": "ctx.containsKey('outer') && ctx['outer'].containsKey('inner') && ctx.outer.inner == 'Y'",
"field": "added_field",
"value": "added_value"
}
}
]
}
}' -u $ES_USER:$ES_PASS
This code is not working and giving me ERROR :
{
"docs" : [
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"ctx.containsKey(outer) && ctx[outer].cont ...",
" ^---- HERE"
],
"script" : "ctx.containsKey(outer) && ctx[outer].containsKey(inner) && ctx.outer.inner == Y",
"lang" : "painless",
"position" : {
"offset" : 16,
"start" : 0,
"end" : 41
}
}
],
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"ctx.containsKey(outer) && ctx[outer].cont ...",
" ^---- HERE"
],
"script" : "ctx.containsKey(outer) && ctx[outer].containsKey(inner) && ctx.outer.inner == Y",
"lang" : "painless",
"position" : {
"offset" : 16,
"start" : 0,
"end" : 41
},
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [outer] is not defined."
}
}
},
Could someone please help me what I am missing in here ...
Reference : [Use conditional if in a Set processor - Elastic Stack / Elasticsearch - Discuss the Elastic Stack](Use conditional if in a Set processor