# Logtash adding filename as index name

**URL:** https://discuss.elastic.co/t/logtash-adding-filename-as-index-name/131487
**Category:** Logstash
**Created:** [May 11, 2018, 2:08pm UTC](https://discuss.elastic.co/t/logtash-adding-filename-as-index-name/131487 "2018-05-11T14:08:44Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [May 11, 2018, 2:42pm UTC](https://discuss.elastic.co/t/logtash-adding-filename-as-index-name/131487/2 "2018-05-11T14:42:41Z")

</div>

```
grok { match => ["path", "/(?<filename>[^/]+).json" ] }

```

will pull out the filename, then you can reference it using 'index =\> "%{filename}"'.

---

_[View the full topic](https://discuss.elastic.co/t/logtash-adding-filename-as-index-name/131487)._
