Getting error SyntaxError: (ruby filter code):3: syntax error, unexpected kIN logstash

(Saket Kumar) #1

I want to split string field "label" which contains hyphen e.g. "Label =SCR1-xyz_abc-Page "
I am trying to split

Scenario= SCR1
Transaction =xyz_abc

But with below config getting syntax error. Any idea why?


csv {
separator => ","
columns => ["timeStamp", "elapsed", "label"]

ruby {
code => "
tmp = event['label']
in = tmp.split('-')
puts tmp
event['Scenario'] = in[0]
event['Transaction'] = in[1]
event['Request'] = in[3]

(Magnus Bäck) #2

I can't spot any errors in that piece of Ruby, but why not just use the mutate filter's split option?

(Saket Kumar) #3

As per my understanding if I use below option it will split the strings in same field 'Label'.
mutate {
split => { "label" => "-" }

Currently I have three columns:
Header: Label|ResponseCode|URL
Value: Thread-group1-transaction_1|200|Null
Value: Thread-group1-transaction_1-Request1|200|
Value: Thread-group1-transaction_1-Request2|200|
Value: Thread-group1-transaction_1-Request3|300|
and so...
However my requirement is to store "Thread-group1-transaction_1-Request" in such a way that when I search for Request; get corresponding column value of URL, when search for transaction get their corresponding value i.e.Null.

I believe storing each segment in separate field will help in searching. Is it posssible to split and store in separate fields.

(Magnus Bäck) #4

The mutate filter's split option can only split into the same field, but there are other options for the mutate filter that can help you create new fields based on each array item in an array field.

(Saket Kumar) #5

I got success using below config and achieved what I wanted too...

mutate {
split => { "label" => "-" }
add_field => { "Scenario" => "%{[label][0]}" }
add_field => { "Transaction" => "%{[label][1]}" }
add_field => { "Request" => "%{[label][2]}" }


(system) #6