# String to Date while loading data from csv file to elasticsearch using logstash

**URL:** <https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479>\
**Category:** Logstash\
**Created:** [September 5, 2017, 7:36pm UTC](https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479 "2017-09-05T19:36:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [September 5, 2017, 7:36pm UTC](https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479/1 "2017-09-05T19:36:21Z")

</div>

I'm using the apple stock as sample data.  
Here I have Date field which is being changed to string type when loading the data.

the format of date in csv file is "dd-MM-YYY"

I want to load this Date as a 'date type' to my index.

please help!!

This is my config file

input{

```
file{

	path => ["/home/apple.csv"]

	start_position => "beginning"

}

```

}

filter {

```
date {
 match => ["Date", "dd-MM-YYYY"]

```

}

```
  csv {

  separator => ","

  columns => ["Date","Open","High","Low","Close","Volume","Adj Close"]

```

}

mutate {convert =\> ["High", "float"]}

mutate {convert =\> ["Open", "float"]}

mutate {convert =\> ["Low", "float"]}

mutate {convert =\> ["Close", "float"]}

mutate {convert =\> ["Volume", "float"]}

}

output {

```
elasticsearch {

    action => "index"

    hosts => "localhost"

    index => "stock"

    workers => 1

}

stdout {}

```

}

---

<div class="post-metadata">

**Author:** ![karanshah](https://avatars.discourse-cdn.com/v4/letter/k/3be4f8/32.png) [@karanshah](https://discuss.elastic.co/u/karanshah)\
**Post date:** [September 5, 2017, 8:11pm UTC](https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479/2 "2017-09-05T20:11:30Z")

</div>

@devil_srj7: is this the complete logstash config? Can you please add how you are getting the date as string in Date field?

Irrespective of that you need to mind that elastic search works on timestamp fields to build time series data so your date should preferably also have a time part.

Can you provide a sample of date & data you are dealing with.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 5, 2017, 8:48pm UTC](https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479/3 "2017-09-05T20:48:13Z")

</div>

You must have the date filter after the csv filter as the field otherwise does not exist when the date filter tries to access it.

---

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [September 6, 2017, 6:43am UTC](https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479/4 "2017-09-06T06:43:00Z")

</div>

The data that I have!!

Date,Open,High,Low,Close,Adj Close,Volume  
05-09-2000,4.475443,4.580357,4.446429,4.459821,4.012305,74660600  
06-09-2000,4.383929,4.455357,4.125,4.174107,3.75526,88851000  
07-09-2000,4.223214,4.46875,4.160714,4.428571,3.98419,54366200  
08-09-2000,4.401786,4.401786,4.178571,4.205357,3.783375,48879600  
11-09-2000,4.191964,4.3125,4.151786,4.174107,3.75526,46845400  
12-09-2000,4.095979,4.290179,4.071429,4.125,3.711082,46999400  
13-09-2000,4.053571,4.25,4.053571,4.142857,3.727146,76496000  
14-09-2000,4.183036,4.258929,4.058036,4.061378,3.653844,106638000  
15-09-2000,4.125,4.15625,3.875,3.945307,3.54942,98628600  
18-09-2000,3.946429,4.339286,3.933036,4.332586,3.897837,106134000  
19-09-2000,4.267857,4.321429,4.183036,4.28125,3.851651,67877600  
20-09-2000,4.2433,4.388393,4.183036,4.360486,3.922938,56847000  
21-09-2000,4.178571,4.258929,3.946429,4.049107,3.642803,127622600  
22-09-2000,3.59375,3.745536,3.571429,3.727679,3.353629,181675200  
25-09-2000,3.767857,3.964286,3.71875,3.821429,3.437971,108887800  
26-09-2000,3.808036,3.910714,3.669643,3.674107,3.305432,72734200  
27-09-2000,3.696429,3.767857,3.446429,3.495536,3.14478,100564800  
28-09-2000,3.522321,3.84375,3.4375,3.821429,3.437971,244896400  
29-09-2000,2.013393,2.071429,1.8125,1.839286,1.654725,1855410200  
02-10-2000,1.90625,1.910714,1.678571,1.732143,1.558333,606197200  
03-10-2000,1.78125,1.785714,1.584821,1.59375,1.433827,509530000  
04-10-2000,1.598214,1.696429,1.5625,1.6875,1.518169,366506000  
05-10-2000,1.678571,1.75,1.571429,1.575893,1.417761,218251600  
06-10-2000,1.620536,1.638393,1.5,1.584821,1.425794,153164200  
09-10-2000,1.616071,1.633929,1.508929,1.553571,1.39768,149391200  
10-10-2000,1.544643,1.602679,1.464286,1.491071,1.341451,172775400  
11-10-2000,1.4375,1.5,1.366071,1.401786,1.261125,299605600  
12-10-2000,1.450893,1.486607,1.392857,1.428571,1.285223,297766000

---

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [September 6, 2017, 6:53am UTC](https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479/5 "2017-09-06T06:53:41Z")

</div>

Thanks it worked !!👍👍👍

---

<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:** [October 4, 2017, 6:53am UTC](https://discuss.elastic.co/t/string-to-date-while-loading-data-from-csv-file-to-elasticsearch-using-logstash/99479/6 "2017-10-04T06:53:49Z")

</div>

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