# Parsing CSV file to Logstash and Elastic Search which is in the server

**URL:** https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444
**Category:** Logstash
**Created:** [February 12, 2018, 9:58am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444 "2018-02-12T09:58:16Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![bpk](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bpk](https://discuss.elastic.co/u/bpk)
#### Post date: [February 12, 2018, 9:58am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/1 "2018-02-12T09:58:16Z")

</div>

Hi,

**I am a Beginner.** Hardly 10 days of experience in Logstash.

I have a csv file (Unstructured). I have copied it to the server, where Logstash is been configured.  
I am trying to parse CSV file into Logstash, But I am getting an error. Kinldy check my code below and help me to correct it.

**###### Code #######**  
input {  
file {  
path =\> "filepathandname"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}  
filter {  
csv {  
separator =\> ","  
columns =\> ["name","product\_name","id","name","status","mdisk\_count","vdisk\_count","capacity","extent\_size","free\_capacity","virtual\_capacity","used\_capacity","real\_capacity","overallocation","warning","easy\_tier","easy\_tier\_status","compression\_active","compression\_virtual\_capacity","compression\_compressed\_capacity","compression\_uncompressed\_capacity","parent\_mdisk\_grp\_id","parent\_mdisk\_grp\_name","child\_mdisk\_grp\_count","child\_mdisk\_grp\_capacity","type","encrypt"]  
}  
}  
output {  
elasticsearch {  
hosts =\> "serverip"  
index =\> "host\_data"  
}  
stdout { }  
}

 ![img](https://us1.discourse-cdn.com/elastic/original/3X/7/a/7a6ebfd46a4c31105a304da8f0aa33979a71ddda.jpg)

---

<div class="post-metadata">

### Author: ![Gaurav\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/g/9fc29f/32.png) [@Gaurav\_Agarwal](https://discuss.elastic.co/u/Gaurav_Agarwal)
#### Post date: [February 12, 2018, 11:43am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/2 "2018-02-12T11:43:26Z")

</div>

I have worked on similar lines I m sharing my code check if this helps

input{  
file{  
path =\> "path of the file"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}  
filter{  
csv{

separator =\> ","

columns =\> ["maker", "model", "mileage", "manufacture\_year", "engine\_displacement", "engine\_power", "body\_type", "color\_slug", "stk\_year", "transmission", "door\_count", "seat\_count", "fuel\_type", "data\_created", "date\_last\_seen", "price\_eur"]

}  
mutate {convert =\> ["mileage", "integer"]}  
mutate {convert =\> ["price\_eur", "float"]}  
mutate {convert =\> ["engine\_power", "integer"]}  
mutate {convert =\> ["door\_count", "integer"]}  
mutate {convert =\> ["seat\_count", "integer"]}  
}  
output{  
elasticsearch {

hosts =\> "localhost"  
index =\> "cars"  
document\_type =\> "sold\_cars"  
}  
stdout{}  
}

So this is basically a list of cars with all the various tags as mentioned it works fine try once following the same

---

<div class="post-metadata">

### Author: ![bpk](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bpk](https://discuss.elastic.co/u/bpk)
#### Post date: [February 12, 2018, 11:48am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/3 "2018-02-12T11:48:05Z")

</div>

Thanks. I will try right now. But in your code, I couldn't see a date field. As per my understanding, Logstash and Elastic Search works on recognizing the Date field. Correct me, If I am wrong ?

---

<div class="post-metadata">

### Author: ![Gaurav\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/g/9fc29f/32.png) [@Gaurav\_Agarwal](https://discuss.elastic.co/u/Gaurav_Agarwal)
#### Post date: [February 12, 2018, 11:58am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/4 "2018-02-12T11:58:05Z")

</div>

It is not a mandate it depends on your needs if the date field is very much critical for you then u can opt for it

---

<div class="post-metadata">

### Author: ![bpk](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bpk](https://discuss.elastic.co/u/bpk)
#### Post date: [February 12, 2018, 12:24pm UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/5 "2018-02-12T12:24:42Z")

</div>

The below is my csv data

'LATITUDE','LONGITUDE'  
'13.98','80.34'  
'14.98','81.34'  
'15.98','82.34'  
'16.98','83.34'  
'17.98','84.34'  
'18.98','85.34'

Now Please find my config file below

input{  
file{  
path =\> "/home/xadmin/qwerty/demolog.csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}  
filter{  
csv{  
separator =\> ","  
columns =\> ["LATITUDE", "LONGITUDE"]  
}  
mutate{convert=\>["LATITUDE","float"]  
mutate{convert=\>["LONGITUDE","float"]  
}  
output{  
elasticsearch{  
hosts =\> "9.xx.xx.xxx:xxxx"  
index =\> "datalong"  
document\_type=\>"longlat"  
}  
stdout{}  
}

\*\* ERROR\*\*  
[2018-02-12T07:14:33,653][ERROR][logstash.agent] Failed to execute action {:action=\>LogStash::PipelineAction::Create/pipeline\_id:main, :exception=\>"LogStash::ConfigurationError", :message=\>"Expected one of #, =\> at line 14, column 11 (byte 272) after filter{\n csv{\n\tseparator =\> ","\n columns =\> ["LATITUDE", "LONGITUDE"]\n\t}\n mutate{convert=\>["LATITUDE","float"]\n mutate", :backtrace=\>["/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:42:in `compile_imperative'", "/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:50:in`compile\_graph'", "/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:12:in `block in compile_sources'", "org/jruby/RubyArray.java:2486:in`map'", "/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:11:in `compile_sources'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:51:in`initialize'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:171:in `initialize'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/create.rb:40:in`execute'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:335:in `block in converge_state'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:141:in`with\_pipelines'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:332:in `block in converge_state'", "org/jruby/RubyArray.java:1734:in`each'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:319:in `converge_state'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:166:in`block in converge\_state\_and\_update'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:141:in `with_pipelines'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:164:in`converge\_state\_and\_update'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:90:in `execute'", "/usr/share/logstash/logstash-core/lib/logstash/runner.rb:343:in`block in execute'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/stud-0.0.23/lib/stud/task.rb:24:in `block in initialize'"]}

---

<div class="post-metadata">

### Author: ![Gaurav\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/g/9fc29f/32.png) [@Gaurav\_Agarwal](https://discuss.elastic.co/u/Gaurav_Agarwal)
#### Post date: [February 13, 2018, 8:18am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/6 "2018-02-13T08:18:19Z")

</div>

try latitude as string because latitude has many points right as in degree,seconds,hour etc.  
I guess that is why this error is popping up

---

<div class="post-metadata">

### Author: ![Gaurav\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/g/9fc29f/32.png) [@Gaurav\_Agarwal](https://discuss.elastic.co/u/Gaurav_Agarwal)
#### Post date: [February 13, 2018, 8:19am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/7 "2018-02-13T08:19:10Z")

</div>

In mutate use["LATITUDE","string"]  
or else if u do not use mutate also then it will by default take it as string

---

<div class="post-metadata">

### Author: ![bpk](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bpk](https://discuss.elastic.co/u/bpk)
#### Post date: [March 6, 2018, 6:28am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/8 "2018-03-06T06:28:31Z")

</div>

Thanks for the help. I have done this using Curl command.

---

<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: [April 3, 2018, 6:28am UTC](https://discuss.elastic.co/t/parsing-csv-file-to-logstash-and-elastic-search-which-is-in-the-server/119444/9 "2018-04-03T06:28:43Z")

</div>

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