# Get the name of the log file and create a tag or a custom field with that value

**URL:** <https://discuss.elastic.co/t/get-the-name-of-the-log-file-and-create-a-tag-or-a-custom-field-with-that-value/274344>\
**Category:** Logstash\
**Created:** [May 28, 2021, 1:01pm UTC](https://discuss.elastic.co/t/get-the-name-of-the-log-file-and-create-a-tag-or-a-custom-field-with-that-value/274344 "2021-05-28T13:01:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mar-ro](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mar-ro](https://discuss.elastic.co/u/mar-ro)\
**Post date:** [May 28, 2021, 1:01pm UTC](https://discuss.elastic.co/t/get-the-name-of-the-log-file-and-create-a-tag-or-a-custom-field-with-that-value/274344/1 "2021-05-28T13:01:16Z")

</div>

Good afternoon.  
I would like to know how I could in logstash create a tag (or a custom field) with a part of the value of the `log.file.path.keyword` field. Considering that this field stores the absolute path, I would be interested in getting only the file name.

I have tried several options, among them the following one, but I can't get this value

```auto
grok {
match => ["log.file.path.keyword" , "(?<filename>[a-zA-Z0-9.]*$)"]]
overwrite => ["filename"]
}

```

Can you tell me how to properly configure logstash to get that value?  
Thanks!

---

<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 28, 2021, 4:58pm UTC](https://discuss.elastic.co/t/get-the-name-of-the-log-file-and-create-a-tag-or-a-custom-field-with-that-value/274344/2 "2021-05-28T16:58:12Z")

</div>

The grok pattern looks right, but .keyword is an elasticsearch thing and that field does not exist in logstash. You probably want

```
match => { "[log][file][path]" => "(?<filename>[a-zA-Z0-9.]*$)" ] }

```

logstash uses a different syntax to represent objects that have nested fields. It can easily distinguish between [foo.bar] (a field with a dot in its name) and [foo][bar] (and object with a field called bar in it).

---

<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:** [June 25, 2021, 4:58pm UTC](https://discuss.elastic.co/t/get-the-name-of-the-log-file-and-create-a-tag-or-a-custom-field-with-that-value/274344/3 "2021-06-25T16:58:38Z")

</div>

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