# Determining Elasticsearch index from message

**URL:** <https://discuss.elastic.co/t/determining-elasticsearch-index-from-message/57121>\
**Category:** Logstash\
**Created:** [August 3, 2016, 3:06pm UTC](https://discuss.elastic.co/t/determining-elasticsearch-index-from-message/57121 "2016-08-03T15:06:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tsury](https://avatars.discourse-cdn.com/v4/letter/t/71c47a/32.png) [@Tsury](https://discuss.elastic.co/u/Tsury)\
**Post date:** [August 3, 2016, 3:06pm UTC](https://discuss.elastic.co/t/determining-elasticsearch-index-from-message/57121/1 "2016-08-03T15:06:40Z")

</div>

Hi.

I am getting the following message from a Kafka input and would like to determine the Elasticsearch index from it:

`{ "@timestamp": "2016-08-03T14:58:39.964Z", "@version": "1", "message": "{\"@timestamp\":\"2016-08-03T14:58:20.381Z\",\"beat\":{\"hostname\":\"MyPC\",\"name\":\"MyPC\"},\"input_type\":\"log\",\"message\":\"{\\\"index\\\":\\\"MyIndex\\\"}\",\"offset\":6639,\"source\":\"d:\\\\tst.log\",\"type\":\"log\"}" }`

As you can see there's a "index" : "MyIndex" field inside the internal message JSON (it originally came from FileBeat).

How can I use this field to set 'MyIndex" as the Elasticsearch index?

Thanks.

---

<div class="post-metadata">

**Author:** ![Joe\_Lawson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_lawson/32/3390_2.png) [@Joe\_Lawson](https://discuss.elastic.co/u/Joe_Lawson)\
**Post date:** [August 3, 2016, 6:05pm UTC](https://discuss.elastic.co/t/determining-elasticsearch-index-from-message/57121/2 "2016-08-03T18:05:40Z")

</div>

You should reconfigure the input creating this message to use codec =\> json {} because you have a json message. After that, you can use [Event Dependent Configuration](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#sprintf)

---

<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:** [July 6, 2017, 4:45am UTC](https://discuss.elastic.co/t/determining-elasticsearch-index-from-message/57121/3 "2017-07-06T04:45:03Z")

</div>


