# I want to read key value kafka headers

**URL:** <https://discuss.elastic.co/t/i-want-to-read-key-value-kafka-headers/344711>\
**Category:** Logstash\
**Created:** [October 10, 2023, 8:45am UTC](https://discuss.elastic.co/t/i-want-to-read-key-value-kafka-headers/344711 "2023-10-10T08:45:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayushi\_bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayushi_bhardwaj/32/109915_2.png) [@Ayushi\_bhardwaj](https://discuss.elastic.co/u/Ayushi_bhardwaj)\
**Post date:** [October 10, 2023, 8:45am UTC](https://discuss.elastic.co/t/i-want-to-read-key-value-kafka-headers/344711/1 "2023-10-10T08:45:40Z")

</div>

Hello I want to read key value kafka headers but it is not giving me any output Can anyone please help me with the configuration or piece of code to read key value from kafka headers.  
My old ticket reference -

> [@Creating Headers (with key value) in kafka offset using logstash Configuration](https://discuss.elastic.co/t/creating-headers-with-key-value-in-kafka-offset-using-logstash-configuration/336089/4):
>
> Note:- We are using logstash-integration-kafka (10.12.0-java) plugin. Still we are not able create or write payload/value to Headers.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [October 10, 2023, 11:09am UTC](https://discuss.elastic.co/t/i-want-to-read-key-value-kafka-headers/344711/2 "2023-10-10T11:09:30Z")

</div>

Hello,

Can you provide more context? Your old post was about creating headers with the Kafka output, is this the same issue?

If so, nothing changes since then, this is still not supported.

---

<div class="post-metadata">

**Author:** ![Ayushi\_bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayushi_bhardwaj/32/109915_2.png) [@Ayushi\_bhardwaj](https://discuss.elastic.co/u/Ayushi_bhardwaj)\
**Post date:** [October 11, 2023, 6:06am UTC](https://discuss.elastic.co/t/i-want-to-read-key-value-kafka-headers/344711/3 "2023-10-11T06:06:28Z")

</div>

Hello Currently we are consuming data from from kafka topic which has headers also configured in that kafka topic .. I want to read the headers with key and value using logstash configuration

```auto
input {
  kafka {
    bootstrap_servers => "your_kafka_broker"
    topics => ["your_topic"]
    codec => "json"
    consumer_threads => 1
    decorate_events => true
  }
}

filter {
  ruby {
    code => '
      headers = event.get("[@metadata][kafka][headers]")
      if headers
        headers.each { |key, value|
          event.set("header_#{key}", value)
        }
      end
    '
  }
}

output {
  stdout {
    codec => rubydebug
  }
} 

```

Above is my code which i am using to read headers from kafka topic but i see no results.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [October 11, 2023, 11:00am UTC](https://discuss.elastic.co/t/i-want-to-read-key-value-kafka-headers/344711/5 "2023-10-11T11:00:47Z")

</div>

> [@Ayushi\_bhardwaj](#):
>
> `decorate_events => true`

It seems that you need to use set this as [extended](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-kafka.html#plugins-inputs-kafka-decorate_events) to get the `headers` field.

From the documentation:

> - `extended`: record’s attributes, headers are added

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 8, 2023, 11:01am UTC](https://discuss.elastic.co/t/i-want-to-read-key-value-kafka-headers/344711/6 "2023-11-08T11:01:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
