we write our Tomcat Log files in JSON by using log4j2 JSONLayout.
Each log file event is a single line with a whole JSON in it and the log file is parsed by using filebeat.
I know I can parse the JSON by using the JSON extractor from the Filter Chain, but I like to use the pipeline processor for it.
The number of JSON fields and values depends on the classes and is different in the log events.
Is it possible to parse an unknown JSON by using pipelines? I can only find possibilities to map known JSON keys and values.
I have a whole JSON directly in the message field. Therefore I must parse the whole message.
When I use the function I get an error, that I a Map is expected but a JsonNode found.
let json_fields = parse_json(to_string($message));
set_fields(json_fields);
$message is an object which represents the currently processed message, not a specific field in that message.
If you want to access the field named “message”, you have to use $message.message.
To be honest, we’d better have named $message differently, e. g. $context or $ctx (similar to Elasticsearch’s Painless scripting), but now it’s too late for that…
Your right, but this was my fault.
Even if I declare $message.message, I always get an JsonNode and no Map and it is not possible to use the set_fields function.
let json_tree = parse_json(to_string($message.message));
set_fields(json_tree);