Here is a json format message in kafka.
{
"@timestamp": "2021-08-14T11:11:00.301Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "7.14.0"
},
"message": {
"k1": "v1",
"k2": "v2"
}
}
Then, i use flink talbe to consume data from kafka.
CREATE TABLE table_1
(
`message` ROW(k1 STRING, k2 STRING)
)
WITH (
'connector' = 'kafka',
'topic' = 'topic1',
'json.ignore-parse-errors' = 'true',
'properties.bootstrap.servers' = '127.0.0.1:9092',
'properties.group.id' = 'groupid1',
'scan.startup.mode' = 'earliest-offset',
'format' = 'json'
);
select message.k1, message.k2 from table_v1 LIMIT 10;
The source message is produced by filebeat(output.kafka).Is it posiable to extract the value of message directly in flink table? Such as:
CREATE TABLE table_2
(
`k1` STRING,
`k2` STRING
)
WITH (
'connector' = 'kafka',
'topic' = 'topic1',
'json.ignore-parse-errors' = 'true',
'properties.bootstrap.servers' = '127.0.0.1:9092',
'properties.group.id' = 'groupid1',
'scan.startup.mode' = 'earliest-offset',
'format' = 'json'
);
select k1, k2 from table_v2 LIMIT 10;