# How to use grok to match filenames as indexes in logstash

**URL:** https://discuss.elastic.co/t/how-to-use-grok-to-match-filenames-as-indexes-in-logstash/262840
**Category:** Logstash
**Created:** [February 1, 2021, 1:14pm UTC](https://discuss.elastic.co/t/how-to-use-grok-to-match-filenames-as-indexes-in-logstash/262840 "2021-02-01T13:14:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ThePreMan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thepreman/32/82548_2.png) [@ThePreMan](https://discuss.elastic.co/u/ThePreMan)
#### Post date: [February 1, 2021, 1:14pm UTC](https://discuss.elastic.co/t/how-to-use-grok-to-match-filenames-as-indexes-in-logstash/262840/1 "2021-02-01T13:14:55Z")

</div>

We try to use developer names as indexes in logstash.  
Therefore our filenames are something like: developer1.log  
We have tried to use grok to match a certain part of the path as our filename. Nothing seems to be working-

We ship from filebeat to logstash.  
This is our logstash conf.:

```auto
    input {
      beats {
        port => 5044
        client_inactivity_timeout => 84600
      }
    }
    filter {
      dissect {
        mapping => {
          "message" => "%{Index} %{timestamp} %{+timestamp} %{PTimestamp} %{Count} %{Ecuid} %{Apid} %{Ctid} %{SessionID} %{Type} %{Subtype} %{Mode} %{#Args} %{Payload}"
        }
      }
      grok { 
        match => ["path" => "/(?<filename>[^/]+).log" ]
      }
      mutate {
        convert => {
          "PTimestamp" => "integer"
          "Count" => "integer"
          "Index" => "integer"
          "#Args" => "integer"
        }
      }
      date {
        match => ["timestamp", "yyyy/MM/dd HH:mm:ss.SSSSSS"]
      }
    }

    output {
      elasticsearch {
        hosts => ["http://elasticsearch-master:9200"]
        index => "%{filename}"
      }
    }

```

---

<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: [March 1, 2021, 1:15pm UTC](https://discuss.elastic.co/t/how-to-use-grok-to-match-filenames-as-indexes-in-logstash/262840/2 "2021-03-01T13:15:46Z")

</div>

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