How to Extract Nested Keys from JSON in Fluent Bit
This post summarizes how I handled extracting nested keys from the container logs of an ECS Service.
The full implementation is available at https://github.com/kenzo0107/sample-fluentbit-get-nested-key.
When you only want the contents of the key log
- Log
1 | { |
1 | docker run --rm -it \ |
Extracted successfully.
When you only want the contents of b inside the key log
1 | { |
1 | docker run --rm -it \ |
Extracted successfully.
When you only want the contents of the list b inside the key log (part 2)
- Log
1 | { |
1 | docker run --rm -it \ |
Because b is not a map type, it could not be extracted with nest.
Handling it with a Lua script
We pass the records through the following Lua script to retrieve the contents of the b key.
1 | function cb_split(tag, timestamp, record) |
1 | [Filter] |
1 | docker run --rm -it \ |
Extracted successfully.
Summary
Regarding the Value of key 'xxx' is not a map. Will not attempt to lift from here error,
I was able to handle it with a very simple script using the Lua script described in Fluent Bit’s official manual.
That’s all.
I hope you find this helpful.
How to Extract Nested Keys from JSON in Fluent Bit
https://kenzo0107.github.io/en/2022/03/25/fluentbit-get-key-from-nested-list/
