How to convert a nested json to string?
Closed this issue · 7 comments
abcfy2 commented
Here is my rubydebug
output:
{
"@timestamp" => 2016-04-01T06:17:16.494Z,
"host" => "shifudao",
"type" => "rtds",
"loglevel" => "WARN",
"classname" => "hawkeyes.rtds.gate.protocol.frametype.SamplerReportData",
"logdetail" => {
"message" => "设备00004650数据上报帧里的sid为空,可能未发过心跳,丢弃!",
"action" => "fireEquipmentDataArrived(String writeHandlerID, String sid, Vertx vertx, List result)",
"sid" => nil,
"params" => {
"writeHandlerID" => "b6728301-653e-488c-91b8-fc2aa52c1312",
"sid" => nil,
"result" => [
[0] {
"eId" => "00004650",
"date" => 963328184494,
"items" => [
[0] [
[0] 1,
[1] [
[0] 74,
[1] 0,
[2] 0,
[3] 0
]
],
[1] [
[0] 2,
[1] [
[0] -119,
[1] 0,
[2] 0,
[3] 0
]
],
[2] [
[0] 3,
[1] [
[0] 12,
[1] 0,
[2] 0,
[3] 0
]
],
[3] [
[0] 4,
[1] [
[0] 12,
[1] 0,
[2] 0,
[3] 0
]
],
[4] [
[0] 5,
[1] [
[0] 110,
[1] 5,
[2] 0,
[3] 0
]
],
[5] [
[0] 6,
[1] [
[0] 61,
[1] 5,
[2] 0,
[3] 0
]
],
[6] [
[0] 7,
[1] [
[0] -18,
[1] 5,
[2] 0,
[3] 0
]
],
[7] [
[0] 8,
[1] [
[0] 3,
[1] 8,
[2] 0,
[3] 0
]
],
[8] [
[0] 9,
[1] [
[0] 0,
[1] 0,
[2] 0,
[3] 0
]
]
]
}
]
}
},
"@version" => "1"
}
I want to convert logdetail.params
to a string
.
But it seems not support by mutate now. How could I do ? And would this feature be add in the future?
ph commented
You need custom ruby code for that, you might to check the https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html
abcfy2 commented
Thanks. Would you please give me an example? I'm not good at ruby, thanks.
abcfy2 commented
I've already fix.
slan77 commented
Could you share the way? I have the same issue now. Thanks!
guangwong commented
+1
shenshouer commented
+1 @abcfy2
shenshouer commented
I got it just like:
ruby {
code => 'event.set("body", event.get("rbody").to_s)'
}