I have this json file
{
"type": "resource",
"headers": {
"destination_channel": "data"
},
"body": {
"type":"resource",
"resourceId":"estimatorB",
"resourceType":null,
"resourceValue":"data.csv",
"resourceSettings":{
},
"resourceContext":{
},
"p_id":"123",
"b_id":"block_789"
}
}
and I need to take only three fields and push them to Elasticsearch, which they're:
resourceValue
p_id
b_id
here is the code I'm using
input {
file {
path => "/usr/share/input/test.json"
start_position => beginning
sincedb_path => "/dev/null"
}
}
filter {
json {
source => "message"
}
ruby {
code => '
arrayOfEvents = Array.new()
ts = event.get("[body]")
ts.each do |k,v|
if k == "resourceValue"
arrayOfEvents.push(data)
elsif k == "pipelineId"
arrayOfEvents.push(data)
elsif k == "blockId"
arrayOfEvents.push(data)
end
end
arrayOfEvents.push(data)
event.set("event",arrayOfEvents)
'
}
split { field => "event" }
}
output {
stdout {}
}
but it throws an exception ruby split error !