hi
sorry if its repeat question. In my document there are few fields which are array of json objects. I want to extract one of json array object's value and assign it to my new field. So for that i m using ruby code to convert an array of json objects in to flat json , copying it to tmp field and then trying to extract value from temp field but its not working.
Here is my logstash conf.
input {
beats {
port => 5044
}
} filter {
json {
source => "message"
}
ruby {
code => '
event.set("request_http_headers_tmp",event.get("request_http_headers").to_json)
'
}
if "transaction-id" in [request_http_headers_tmp]
{
mutate{
add_field => { "transaction-id" => "%{request_http_headers_tmp.transaction-id}" }
}
}
mutate {
remove_field => [ "@version","fields","tags","host","agent","log","message","version","request_http_headers" ]
}
}
output {
stdout {
codec => rubydebug
}
}
Here is my sample input
{"request_http_headers":[{"transaction-id": "1234" },{"raj":"test"}]}
{"request_http_headers":[{"TraceId":"9d912b9aedf0f0d6"},{"Request-Id":"a58db2fb"},{"Sampled":"0"},{"SpanId":"109996b844d56118"},{"ParentSpanId":"afd752b39e"},{"Via":"1.1 AgAAALgHxKA-"},{"X-Client-IP":"1.1.1.1"},{"transaction-id":"ecbc4be05f0c88ff00c11f61"}]}
Here is my output
"request_http_headers_tmp" => "[{\"transaction-id\":\"1234\"},{\"raj\":\"test\"}]",
"ecs" => {
"version" => "1.0.1"
},
"transaction-id" => "%{request_http_headers_tmp.transaction-id}",
"@timestamp" => 2020-07-13T17:56:31.709Z
}
{
"request_http_headers_tmp" => "[{\"TraceId\":\"9d912b9aedf0f0d6\"},{\"Request-Id\":\"a58db2fb\"},{\"Sampled\":\"0\"},{\"SpanId\":\"109996b844d56118\"},{\"ParentSpanId\":\"afd752b39e\"},{\"Via\":\"1.1 AgAAALgHxKA-\"},{\"X-Client-IP\":\"1.1.1.1\"},{\"transaction-id\":\"ecbc4be05f0c88ff00c11f61\"}]",
"ecs" => {
"version" => "1.0.1"
},
"transaction-id" => "%{request_http_headers_tmp.transaction-id}",
"@timestamp" => 2020-07-13T17:56:31.709Z
}
any clue on what am i doing wrong ?