# Logstash date conversion from string to date not working

**URL:** <https://discuss.elastic.co/t/logstash-date-conversion-from-string-to-date-not-working/123699>\
**Category:** Logstash\
**Created:** [March 13, 2018, 9:09am UTC](https://discuss.elastic.co/t/logstash-date-conversion-from-string-to-date-not-working/123699 "2018-03-13T09:09:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahir/32/28678_2.png) [@ahir](https://discuss.elastic.co/u/ahir)\
**Post date:** [March 13, 2018, 9:09am UTC](https://discuss.elastic.co/t/logstash-date-conversion-from-string-to-date-not-working/123699/1 "2018-03-13T09:09:12Z")

</div>

Hi,  
I am a beginner in the elastic stack. I have a CSV file, contents of which I want to load into elastic search. In the CSV there is a "date" column which has dates in the following format:

2/27/2018  
M/d/yyyy

I am trying to convert the string date values to date type but failed. I have searched on the net a lot, but still having the same problem going on.

Here is my config file:-

```
        input {
      file {
        path => "/Users/ahir.chattopadhyay/AAPL.csv"
        start_position => "beginning"
    	sincedb_path => "nul"
    	type => "csv"
      }
    }
    filter {  
      if ([message] =~ "\bDate\b") {
            drop { }
        } else {
    		csv {
    		  separator => ","
    		  columns => ["Date","Open","High","Low","Close","Volume","Adj Close"]
    		}
    		date {
    			match => ["date", "M/d/yyyy"]
    			target => "date"
    			locale => "en"
    		}
    	  mutate {
    		convert => {
    		  "High" => "float"
    		  "Open" => "float"
    		  "Low" => "float"
    		  "Close" => "float"
    		  "Volume" => "float"
    		}
    	  }
    	}
    }
    output {  
        elasticsearch {
            action => "index"
            hosts => "localhost:9200"
            index => "stock_data"
            workers => 1
        }
        stdout {}
    }

```

While running it from cmd, I am getting following error:

`[logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"stock_data", :_type=>"doc", :_routing=>nil}, #<LogStash::Event:0x201f7c23>], :response=>{"index"=>{"_index"=>"stock_data", "_type"=>"doc", "_id"=>"9hquHmIBX6AI3pdfu73f", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [Date]", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"Invalid format: \"3/5/2018\" is malformed at \"/5/2018\""}}}}}`

I think the error is related to date format.  
Any help would be appreciated.

---

<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:** [March 13, 2018, 11:00am UTC](https://discuss.elastic.co/t/logstash-date-conversion-from-string-to-date-not-working/123699/2 "2018-03-13T11:00:32Z")

</div>

27 is two digits so you need "dd" rather than "d" in your date pattern.

If you also have single-digits day-of-month numbers (i.e. leading zeroes aren't used) you need to specify multiple date patterns:

```
match => ["date", "M/d/yyyy", "M/dd/yyyy", "MM/d/yyyy", "MM/dd/yyyy"]
```

---

<div class="post-metadata">

**Author:** ![ahir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahir/32/28678_2.png) [@ahir](https://discuss.elastic.co/u/ahir)\
**Post date:** [March 13, 2018, 11:17am UTC](https://discuss.elastic.co/t/logstash-date-conversion-from-string-to-date-not-working/123699/3 "2018-03-13T11:17:15Z")

</div>

I've modified the config file as per your suggestions. Now the error is not coming but the date type is still getting stored as string in elastic

---

<div class="post-metadata">

**Author:** ![ahir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahir/32/28678_2.png) [@ahir](https://discuss.elastic.co/u/ahir)\
**Post date:** [March 13, 2018, 12:42pm UTC](https://discuss.elastic.co/t/logstash-date-conversion-from-string-to-date-not-working/123699/4 "2018-03-13T12:42:12Z")

</div>

It's working. I had mistakenly written "date" - the column name - in lower case, but actually, the 'D' is in upper case. Thanks a lot.

---

<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 10, 2018, 12:42pm UTC](https://discuss.elastic.co/t/logstash-date-conversion-from-string-to-date-not-working/123699/5 "2018-04-10T12:42:37Z")

</div>

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