Ingest Node: Adding new Objects?

Hey there !
Im pulling data from a device via http-module (metricbeat).
Unfortunately the Data is put in mixed datatypes within one array (elasticsearch doesn't support these types of arrays)

First Example

{"_P_SUM3": [260.4908,"W"]}

Second Example

{ "_ULN": [[ 
224.2511,
225.7967,
226.3067],"V"]}

For the first example i was able to create a new field with the script processor.

{
  "testpipeline" : {
    "description" : "Data_Parsing",
    "processors" : [
      {
        "script" : {
          "lang" : "painless",
          "source" : """
          ctx.Psum = ctx.http.Janitza_Monti2._P_SUM3[0];
"""
        },
        "remove" : {
          "field" : [
            "http.Janitza_Monti2._P_SUM3",
          ]
        }
      }
    ]
  }
}

My Question for Example 2 is how do i access these kinds of arrays in the script processor.
I tried using this term:
ctx.cosphi1 = ctx.http.Janitza_Monti2._COS_PHI[0][0];

But that doesn't work.

Second Question: Is it possible to create a field of objects with the script processor ? Like this structure ?

{
"new_field": {
"name": "my_name",
"value": "[value1, value2, value3]"
}
}

painless has this syntax for accessing arrays: i.e. foo[0] to access the first element.

So the second example would be something like ctx._ULN[0][1] to access the 225 value.

Regarding your second question: yes, you can create such a structure.

1 Like

Thanks for the answer,
i was able to access the data in the array :smile: :+1:

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