I am using Kafka-Connect to implement a Kafka-Elasticsearch connector.
The producer sent a complex JSON on to a Kafka Topic and my connector code will use this to persist to Elastic search. The connector get the data in form of Struct(https://kafka.apache.org/0100/javadoc/org/apache/kafka/connect/data/Struct.html).
I am able to get the field values of struct at top level Json but not able to fetch from nested jsons.
{
"after": {
"test.test.employee.Value": {
"id": 5671111,
"name": {
"string": "abc"
}
}
},
"op": "u",
"ts_ms": {
"long": 1474892835943
}
}
I am able to parse "op", but not "test.test.employee.Value".
Struct afterStruct = struct.getStruct("after"); // giving me proper value.
String opValue = struct.getString("op"); // giving me proper value of "u".
Struct valueStruct = afterStruct .getStruct("test.test.employee.Value"); // org.apache.kafka.connect.errors.DataException: test.test.employee.Value is not a valid field name
Struct.getStruct
does not natively support nesting using dot notation.It seems your schema might come from Debezium, in that case, they have their own "unwrap" message transformer.
One option, if you are in control of this extractor code, you might find the code I wrote for the Confluent Kafka Connect Storage project useful. It takes a Struct or a Map object (see below)
Otherwise, you might want to try adding KCQL plugin by Landoop into your Connect classpath.