I wanted to add to this. As an example, after you have processed to map, you could set the fields by type. As an example,
set_field(“nginx_body_bytes_sent”,to_double($message.nginx_body_bytes_sent))
This will not help… we want field to be set dynamically … because I shared example of nginx but we have others too… so setting up field type for each and every field by this suggestion will not help… correct me if i am wrong.
Ok so meanwhile i tried below and it seems it only converted “nginx_body_bytes_sent” field type and kept rest of the field as it is “string”… am I doing anything wrong ?
rule "extract json"
when
regex("(\\{.*\\})", to_string($message.message)).matches == true
then
let json = regex("(\\{.*\\})", to_string($message.message), ["json"])["json"];
// set_field("json", json);
set_fields(to_map(flatten_json(value: to_string(json), array_handler: "json")));
set_field("nginx_body_bytes_sent",to_double($message.nginx_body_bytes_sent));
set_field("nginx_bytes_sent",to_double($message.nginx_bytes_sent));
set_field("nginx_port",to_long($message.nginx_port));
set_field("nginx_request_length",to_double($message.nginx_request_length));
set_field("nginx_request_time",to_double($message.nginx_request_time));
set_field("nginx_site",to_ip($message.nginx_site));
set_field("nginx_status",to_long($message.nginx_status));
end
Hi @brijesh.kalavadia ,
I have tested this new rule with the data in GL V5 RC2 and This change creates the option to parse as strings true or false.
rule "Random User Data Flatten Json Rule"
// From sample data : https://randomuser.me/api/
// Api input path: *
when
true
then
let sJson = to_string($message.result);
let sJson = regex_replace(
pattern: "^\\[|\\]$",
value: sJson,
replacement: ""
);
// let rsJson = flatten_json(to_string(sJson), "flatten");
let rsJson = flatten_json(value: sJson, array_handler: "flatten", stringify: false);
set_fields(to_map(rsJson));
remove_field("result");
set_field("message", "parsed user data");
end
Thanks @jivepig for sharing updates… really appreciate for quick fix… I am waiting for 4.3 bug fix release … once its out … i will test as you suggested.