How to loop through array in Logstash?


I have this data:

"url" => [
      [0] [
          [0] "",
           [1] "data",
            [2] "data1"
[3] "9462"

What I want is that I need to get last element of list as assignment_1 ( I need to assing last data into this variable) and the other things need to placed in assignment_2 as "data/data1".
I though it would be useful if have used loop over array list but could not figured it out.
Think that my array lenght will be changed all the time.But again, I need last data into assignmet_1 and the other into assingment_2.

I would do that in ruby. Start off with

ruby {
    code => '
        url = event.get("url")
        if url
            event.set("a1", url[0][-1])
            event.set("a2", url[0][0..-2].join("/"))

Thank you so much. It works really good. Especially, I was suffering to code

this part.
This might be a another question but when I split a field logstash deletes its value instead of keeping it. I want to split a field but dont want to loose its value. How am I gonna do that?

You need to show an example of the event input, the filter configuration, and the resulting event.

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