# How to use filename as index wiht beats input

**URL:** https://discuss.elastic.co/t/how-to-use-filename-as-index-wiht-beats-input/128467
**Category:** Logstash
**Created:** [April 18, 2018, 6:57am UTC](https://discuss.elastic.co/t/how-to-use-filename-as-index-wiht-beats-input/128467 "2018-04-18T06:57:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![terminaattori](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@terminaattori](https://discuss.elastic.co/u/terminaattori)
#### Post date: [April 18, 2018, 6:57am UTC](https://discuss.elastic.co/t/how-to-use-filename-as-index-wiht-beats-input/128467/1 "2018-04-18T06:57:40Z")

</div>

Hey!

How can I use the filename as an index when using beats input for multiple files?

My filebeat.yml looks currently like this:

```
filebeat.prospectors:
- type: log
  paths:
    - /path/${CURRENT_SERVER}/*log*
  fields:
     index: ${CURRENT_SERVER}-${DATE_USED}
  close_eof: true
output.logstash:
  hosts: ["localhost:5044"]
output.console:
  enabled: false

```

and pipeline.conf like this:

```
input {

beats {
        port => "5044"
    }

}
filter {
    grok {
        match => { "message" => "%{LOGGERLEVEL:log}%{LOGTYPE:k}%{TIMESTAMP_ISO8601:datetime}%{GREEDYDATA:data}"}
    }
    date {
        match => ["datetime", "ISO8601"]
        timezone => TIMEZONE
    }

}
output {

    elasticsearch {
    	index => "%{[fields][index]}"
        hosts => ["localhost:9200"]
    }

}

```

recently this approach worked just fine when I had one file in a folder, but now I have two or three files in a folder. How can I extract the filename and use it as index?

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [April 18, 2018, 8:29am UTC](https://discuss.elastic.co/t/how-to-use-filename-as-index-wiht-beats-input/128467/2 "2018-04-18T08:29:48Z")

</div>

The event should have a [source field](https://www.elastic.co/guide/en/beats/filebeat/current/exported-fields-log.html#_literal_source_literal).

You can use this field `index => "%{[source]}"`

---

<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: [May 16, 2018, 8:30am UTC](https://discuss.elastic.co/t/how-to-use-filename-as-index-wiht-beats-input/128467/3 "2018-05-16T08:30:02Z")

</div>

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