# Append hostname in each index name

**URL:** https://discuss.elastic.co/t/append-hostname-in-each-index-name/276519
**Category:** Logstash
**Created:** [June 21, 2021, 10:16am UTC](https://discuss.elastic.co/t/append-hostname-in-each-index-name/276519 "2021-06-21T10:16:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![connectgeeks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/connectgeeks/32/90595_2.png) [@connectgeeks](https://discuss.elastic.co/u/connectgeeks)
#### Post date: [June 21, 2021, 10:16am UTC](https://discuss.elastic.co/t/append-hostname-in-each-index-name/276519/1 "2021-06-21T10:16:39Z")

</div>

I would like to append hostname in each index name for classification of files based on the source hostname.

```auto
output{
  elasticsearch {
    hosts => ["127.0.0.1:9200"]
    index => "sample-%{[@metadata][hostname]}-%{[@metadata][beat]}-%{[@metadata][version]}-soap2-%{[@metadata][beat]}-%{+YYYY.MM.dd}"
  }
}

```

This metadata is not working %{[@metadata][hostname]};

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [June 21, 2021, 12:00pm UTC](https://discuss.elastic.co/t/append-hostname-in-each-index-name/276519/2 "2021-06-21T12:00:49Z")

</div>

You might not have a field called `hostname`.

Add this to your output and it will show you all the `metadata` fields available.

` stdout { codec => rubydebug { metadata => true } }`

---

<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 19, 2021, 12:01pm UTC](https://discuss.elastic.co/t/append-hostname-in-each-index-name/276519/3 "2021-07-19T12:01:17Z")

</div>

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