# Add field with logstash (using kafka input plugin)

**URL:** <https://discuss.elastic.co/t/add-field-with-logstash-using-kafka-input-plugin/160358>\
**Category:** Logstash\
**Created:** [December 11, 2018, 11:26am UTC](https://discuss.elastic.co/t/add-field-with-logstash-using-kafka-input-plugin/160358 "2018-12-11T11:26:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yehosef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yehosef/32/42175_2.png) [@yehosef](https://discuss.elastic.co/u/yehosef)\
**Post date:** [December 11, 2018, 11:26am UTC](https://discuss.elastic.co/t/add-field-with-logstash-using-kafka-input-plugin/160358/1 "2018-12-11T11:26:23Z")

</div>

I'm using the kafka input plugin for Logstash and there are metadata fields described in [https://www.elastic.co/guide/en/logstash/current/plugins-inputs-kafka.html](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-kafka.html).

I want to copy some or all the fields into my data for reference/debugging. The use case is basically the same as [Sending @metadata from logstash to elastic search](https://discuss.elastic.co/t/sending-metadata-from-logstash-to-elastic-search/92890)

I tried the following in my filter:

```
mutate {
   add_field => { "kafka_topic"=> "%{[@metadata][kafka][topic]}" }
   add_field => { "kafka_consumer_group"=>"%{[@metadata][kafka][consumer_group]}" }
   add_field => { "kafka_timestamp"=>"%{[@metadata][kafka][timestamp]}" }
}

```

But what I see in Elasticsearch is the literal text for the value (eg. "%{[@metadata][kafka][consumer\_group]}")

I tried the ruby script in the question above, but had some error. It seems like this is a simple thing but I can't figure out how to make it work.

Can someone help?

---

<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:** [January 8, 2019, 11:26am UTC](https://discuss.elastic.co/t/add-field-with-logstash-using-kafka-input-plugin/160358/2 "2019-01-08T11:26:31Z")

</div>

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