Hello, we have a use case where we would like to ingest specific JSON formatted messages into elasticsearch as well as convert the content of the input message into a new output JSON format and write it out to a Kafka topic.
The ingestion into elasticsearch as well as writing the output to the Kafka topic is functional. What I am having difficulty with is the conversion from one JSON schema to the other as I have a nested JSON field. I am currently writing out the new JSON message manually in the pipeline by mutating and adding a new field.
Here is an example of the input message:
{
"sourceSystemId" : "SystemABC",
"externalAlarmId" : "11082807",
"alarmRaisedTime" : "2018-01-01T19:41:01Z",
"alarmType" : "QueueStatus",
"alarmedObject" : {
"id": "DeviceABC",
"resource" : {
"id": "DeviceABC",
"name": "DeviceABC",
"category": "NODE",
"characteristic" : [
{
"name": "NodeAlias",
"value": "192.168.1.1"
},
{
"name": "AlertKey",
"value": "c3-1-1-2"
},
{
"name": "deviceType",
"value": "router"
}
]
}
},
"perceivedSeverity" : "MINOR",
}
By using the JSON codec on the input all fields are extracted and usable with the exception of the nested JSON which creates has an array called:
[alarmedObject][resource][characteristic]
When I construct my new JSON message utilizing this array field the output is stripped of the quotes and colon. Here is my sample config as well as actual output and desired output for reference.
input {
udp {
tags => ["udp"]
port => 50000
codec => json
}
}
filter {
mutate {
add_field => {test_message_3 => '{"additionalAlarmInfo":[%{[alarmedObject][resource][characteristic]}]}'}
}
Current OUTPUT when referencing the contents of nested JSON field. We see that for some reason an "=" sign is added to the content.
{
"additionalAlarmInfo":[
"{name=NodeAlias, value=192.168.1.1},{name=AlertKey, value=c3-1-1-2},{name=deviceType, value=router}"
]
}
Desired OUTPUT which is JSON compliant.
{
"additionalAlarmInfo":[
{
"name": "NodeAlias",
"value": "192.168.1.1"
},
{
"name": "AlertKey",
"value": "c3-1-1-2"
},
{
"name": "deviceType",
"value": "router"
}
]
}
My question is how do I include the as JSON formatted content of the array into a new field? Am I calling the array incorrectly with the following in my new message?
'{"additionalAlarmInfo":[%{[alarmedObject][resource][characteristic]}]}'
I hope this makes sense. Any direction from the community that could be provided would be greatly appreciated. Thank you.