XML plugin + split + ruby code to generate dynamic fields

I have a compplex XML with information about phone network cells we need to parse. I managed to ingest the data using the xml and the split filter in order to have the desired information in separate documents into elastic. So far, so god
Now I have this problem. The documents contains a nested field called poc,mi like this:

  "mt": [
  "mv": {
    "moid": [
      " 1,1,1,1,1,F"
    "r": [

I need to extract the mt value and the r values into arrays inside a ruby code.
I'have tried several ways but no luck

Thank you

What structure do you want to end up with?

Hi @Badger
I solved using the following code (any suggestion is welcome)

  ruby {
            code => "
                     array=[param, values].transpose
                     array.each {|x| event.set(x[0],x[1])}

The structure I need to end up with is:
the values of the mt array as individuals fields whose value is in the r array matching positionally (it is a very ugly XML). See attached.

Any suggestion is welcome

That's the way to do it. Personally I would have written it slightly differently, but it is six of one and half a dozen of the other.

param.each_index {|x| event.set(param[x],values[x])}
1 Like

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