Ingest node script processor issue

Hi All,

I'm trying to create new fields and corresponding value based on the values present in two different arrays while parsing the data in ingest node pipeline. For e.g., Array1 = [num1,num2] and Array2 = [10,20]
Expected output: num1 = 10, num2=20.

I'm trying to achieve this using script processor as shown below:

{"script": {
"lang": "painless",
"inline": "def source_fields = ctx.Array1;def target_fields = ctx.Array2 ;for(def i=0; i<source_fields.length; i++) {
ctx.Array1[i]= target_fields[i]; }"
}}

This one just changes the content or Array1 to [10,20]. Can you please help.

Thanks,
Ashish

try sth like ctx['array' + i] = target_fields[i]

note however that this pretty dangerous as you can easily do a field explosion, so you should maybe cap this somewhere.

Thanks Alexander for your reply. However this is not giving desired results. Its generating two new fields:

Array0: 10
Array1: 20

Expected output is num1=10, num2=20.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.