# How to extract logstash log.file.path for filter

**URL:** https://discuss.elastic.co/t/how-to-extract-logstash-log-file-path-for-filter/239581
**Category:** Logstash
**Created:** [July 2, 2020, 7:31am UTC](https://discuss.elastic.co/t/how-to-extract-logstash-log-file-path-for-filter/239581 "2020-07-02T07:31:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jang](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jang](https://discuss.elastic.co/u/jang)
#### Post date: [July 2, 2020, 7:31am UTC](https://discuss.elastic.co/t/how-to-extract-logstash-log-file-path-for-filter/239581/1 "2020-07-02T07:31:14Z")

</div>

hi.  
I am using Filebeat and Logstash.

now, my [log][file][path] result. (The file path is flexible.)

```auto
/home/logs/tomcat/application/test.log

or

/LOG/application/test2.log

etc...

```

I only want the file name except for the extension.  
example,

```auto
test

or

test2

```

I want to use the extracted file name as the output elasticsearch index by putting it in a variable.  
please help me...

---

<div class="post-metadata">

### Author: ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)
#### Post date: [July 2, 2020, 7:51am UTC](https://discuss.elastic.co/t/how-to-extract-logstash-log-file-path-for-filter/239581/2 "2020-07-02T07:51:16Z")

</div>

You can use a grok filter with this regex:

```
(?<filename>[^\/]*)\.log$
```

---

<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 30, 2020, 7:51am UTC](https://discuss.elastic.co/t/how-to-extract-logstash-log-file-path-for-filter/239581/3 "2020-07-30T07:51:20Z")

</div>

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