# How to pass multiple csv files with different names and different content?

**URL:** <https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389>\
**Category:** Logstash\
**Created:** [February 21, 2019, 10:40am UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389 "2019-02-21T10:40:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thodoris\_Alexopoulos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thodoris_alexopoulos/32/40764_2.png) [@Thodoris\_Alexopoulos](https://discuss.elastic.co/u/Thodoris_Alexopoulos)\
**Post date:** [February 21, 2019, 10:40am UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389/1 "2019-02-21T10:40:23Z")

</div>

Hello,

I want to pass into Elastisearch several CSV files with a different format each other. Till now, I have created a Logstash conf file that handles only one CSV with a specific name under a specific path. But when I am using a \* to catch all the files under the directory the result is not what I want. Below you can find my Logstash conf file and the CSV files. Could anyone give some advice about what I am doing wrong? Thanks in advance.

input {  
file {  
path =\>"/home/kibana/Downloads/scde1\_report\_MTSMS\_2019-02-05.csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}

```
	file {
            path =>"/home/kibana/Downloads/scde1_report_MTSMS_Throttling2019-01-23.csv"
            start_position => "beginning"
            sincedb_path => "/dev/null"
    }

```

}  
filter {  
if [path] == "/home/kibana/Downloads/scde1\_report\_MTSMS\_2019-02-05.csv"  
{  
if ([message] =~ "\bDate\b") {  
drop { }  
} else {  
csv {  
separator =\> ","  
columns =\> ["Date","Hour","Avg\_TPS","Avg\_Top\_1%\_TPS","Avg\_Top\_10%\_TPS","Avg\_Proc","Avg\_Top\_1%\_Proc","Avg\_Top\_10%\_Proc"]

```
    }	}
	}
	else if [path] == "/home/kibana/Downloads/scde1_report_MTSMS_Throttling2019-01-23.csv"
	{
	 if ([message] =~ "\bDate\b") {
    drop { }
} else {
    csv {
            separator => ","
            columns => ["Date","Hour","Avg_TPS","Avg_Top_1%_TPS","Avg_Top_10%_TPS"]

    }	}

```

}  
mutate{

```
            add_field => {
                    "DateHour" => "%{Date} %{Hour}"
                    }
            convert => {
                    "Avg_TPS" => "float"
                    "Avg_Top_1%_TPS" => "float"
                    "Avg_Top_10%_TPS" => "float"
                    "Avg_Proc" => "float"
                    "Avg_Top_1%_Proc" => "float"
                    "Avg_Top_10%_Proc" => "float"
                    }
            }

```

date {  
match =\> ["DateHour","YYYY-MM-dd HH ","ISO8601"]  
timezone =\> "Europe/Athens"  
target =\> "DateHour"  
remove\_field =\> ["message","path","host","Date","Hour"]  
}

}  
output {  
elasticsearch{  
hosts =\> "localhost:9200"  
index =\> "report"  
document\_type =\> "MT\_SMS"  
}  
stdout{}

}

* * *

Config for multiple files

input {  
file {  
path =\>"/home/kibana/Downloads/\*.csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}

```
	file {
            path =>"/home/kibana/Downloads/*.csv"
            start_position => "beginning"
            sincedb_path => "/dev/null"
    }

```

}  
filter {  
if [path] == "/home/kibana/Downloads/\*.csv"  
{  
if ([message] =~ "\bDate\b") {  
drop { }  
} else {  
csv {  
separator =\> ","  
columns =\> ["Date","Hour","Avg\_TPS","Avg\_Top\_1%\_TPS","Avg\_Top\_10%\_TPS","Avg\_Proc","Avg\_Top\_1%\_Proc","Avg\_Top\_10%\_Proc"]

```
    }	}
	}
	else if [path] == "/home/kibana/Downloads/*.csv"
	{
	 if ([message] =~ "\bDate\b") {
    drop { }
} else {
    csv {
            separator => ","
            columns => ["Date","Hour","Avg_TPS","Avg_Top_1%_TPS","Avg_Top_10%_TPS"]

    }	}

```

}  
mutate{

```
            add_field => {
                    "DateHour" => "%{Date} %{Hour}"
                    }
            convert => {
                    "Avg_TPS" => "float"
                    "Avg_Top_1%_TPS" => "float"
                    "Avg_Top_10%_TPS" => "float"
                    "Avg_Proc" => "float"
                    "Avg_Top_1%_Proc" => "float"
                    "Avg_Top_10%_Proc" => "float"
                    }
            }

```

date {  
match =\> ["DateHour","YYYY-MM-dd HH ","ISO8601"]  
timezone =\> "Europe/Athens"  
target =\> "DateHour"  
remove\_field =\> ["message","path","host","Date","Hour"]  
}

}  
output {  
elasticsearch{  
hosts =\> "localhost:9200"  
index =\> "report"  
document\_type =\> "MT\_SMS"  
}  
stdout{}

}

---

<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:** [February 21, 2019, 2:04pm UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389/2 "2019-02-21T14:04:11Z")

</div>

If I am reading it correctly you have

> [@Thodoris\_Alexopoulos](#):
>
> ```auto
> if [path] == "/home/kibana/Downloads/*.csv" {
> [...]
> } else if [path] == "/home/kibana/Downloads/*.csv"
> 
> ```

It is never going to go through the second branch.

---

<div class="post-metadata">

**Author:** ![Thodoris\_Alexopoulos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thodoris_alexopoulos/32/40764_2.png) [@Thodoris\_Alexopoulos](https://discuss.elastic.co/u/Thodoris_Alexopoulos)\
**Post date:** [February 21, 2019, 2:15pm UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389/3 "2019-02-21T14:15:02Z")

</div>

In the first case it is working because under /Downloads/ there is a specific name?

---

<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:** [February 21, 2019, 2:26pm UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389/4 "2019-02-21T14:26:42Z")

</div>

Yes.

---

<div class="post-metadata">

**Author:** ![Thodoris\_Alexopoulos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thodoris_alexopoulos/32/40764_2.png) [@Thodoris\_Alexopoulos](https://discuss.elastic.co/u/Thodoris_Alexopoulos)\
**Post date:** [February 21, 2019, 2:29pm UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389/5 "2019-02-21T14:29:24Z")

</div>

Can you propose me any solution?

---

<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:** [February 21, 2019, 2:42pm UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389/6 "2019-02-21T14:42:35Z")

</div>

You need to have a more specific pattern that only matches the files that have the format that the branch parses. If just the date changes then maybe something like

```
if [path] =~ /scde1_report_MTSMS_Throttling.*\.csv/ {
    [...]
else if [path] =~ /scde1_report_MTSMS.*\.csv/ {
```

---

<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 21, 2019, 2:42pm UTC](https://discuss.elastic.co/t/how-to-pass-multiple-csv-files-with-different-names-and-different-content/169389/7 "2019-03-21T14:42:46Z")

</div>

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