# Get file name from s3 file

**URL:** <https://discuss.elastic.co/t/get-file-name-from-s3-file/102683>\
**Category:** Logstash\
**Created:** [October 4, 2017, 10:41am UTC](https://discuss.elastic.co/t/get-file-name-from-s3-file/102683 "2017-10-04T10:41:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)\
**Post date:** [October 4, 2017, 10:41am UTC](https://discuss.elastic.co/t/get-file-name-from-s3-file/102683/1 "2017-10-04T10:41:51Z")

</div>

Hi  
i have s3 bucket from where i taking csv file and uploading in to ES .  
i stuck on how to get file name which i have in s3 , beacuse i am using s3 file name as Index name .  
My config file -

```
input{
	s3{
	bucket => "***"
	access_key_id => "**"
	secret_access_key => "***"
	region => "**"

}
}

filter {
	csv {
		separator => ","
		columns => ["name","uid","startdate","enddate"]

	}
	mutate {convert =>[uid , "integer"]}
	
	  date {
      match => ["startdate", "ISO8601", "YYYY/MM/dd HH:mm:ss","YYYY/MM/dd HH:mm"]
      target => "startdate"
      locale => "en"
	  timezone => "Asia/Dubai"
    }
	
	  date {
      match => ["enddate", "ISO8601", "YYYY/MM/dd HH:mm","YYYY/MM/dd HH:mm:s"]
      target => "enddate"
      locale => "en"
	  timezone => "Asia/Dubai"
    }
	  mutate {
    add_field => {
      "index_name" => "%{[@metadata][s3][key]}"
    }
   
  }

  }

output {
	elasticsearch {
		hosts => "localhost"
		index => "%{index_name}"
	}
	stdout{}

}

```

Any suggestion

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 4, 2017, 12:14pm UTC](https://discuss.elastic.co/t/get-file-name-from-s3-file/102683/2 "2017-10-04T12:14:32Z")

</div>

Assuming that the S3 path is available in a field in the event you can use a grok filter to extract the name. How to extract a filename from a full path has been asked several times before so you should be able to find examples in the archives.

---

<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:** [November 1, 2017, 12:14pm UTC](https://discuss.elastic.co/t/get-file-name-from-s3-file/102683/3 "2017-11-01T12:14:49Z")

</div>

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