[英]How to get custom key value in the logstash kafka input?
In my producer, I've added a few custom keys in the headers.在我的制作人中,我在标题中添加了一些自定义键。 Using logstash i need to get the payload in addition I need to read the value of my keys.
使用 logstash 我需要获取有效负载,此外我需要读取我的密钥的值。
Producer code:生产者代码:
kafkaTemplate
.send(
MessageBuilder.withPayload(myPayload)
.setHeader(KafkaHeaders.TOPIC, myTopic)
.setHeader("my-key1", "test-key1") // custom keys
.setHeader("my-key2", "test-key2") // custom keys
.build())
Logstash conf Logstash 配置
input{
kafka{
//kafka connection details
decorate_events => true
}
}
filter{
mutate => { add_field => { "kafka-topic" => "%{[@metadata][kafka][topic]}" } // this is working
mutate => { add_field => { "custom-key" => "%{[my-key1]}" } // this is not working
}
output{
// store the payload on ES index, _id = my-key1
}
I'm not able to read my custom key.我无法读取我的自定义密钥。 Did I miss anything in the config?
我错过了配置中的任何内容吗?
In recent Logstash releases, you can set decorate_events => "extended"
(true means basic) and then get headers using:在最近的 Logstash 版本中,您可以设置
decorate_events => "extended"
(true 表示基本),然后使用以下方法获取标头:
%{[@metadata][kafka][headers][my-key1]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.