# How to convert field date from String to Date?

**URL:** <https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467>\
**Category:** Logstash\
**Created:** [March 20, 2020, 6:25pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467 "2020-03-20T18:25:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [March 20, 2020, 6:25pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/1 "2020-03-20T18:25:31Z")

</div>

## I want to convert the field of date from string to date, i try this code in my config file but it doesn't change in kibana..I don't know why! any help??

## filter{ csv{ columns =\> ["car","date","dateEntree","dateSortie"] separator =\> "," } date { match =\> ["date", "dd/MM/YY"] target =\> "date" } }

## in the console when i run the config file he turn this

{  
"date" =\> "05-03-2020",  
"@timestamp" =\> 2020-03-20T17:26:43.463Z,  
"voiture" =\> "V8",  
"dateSortie" =\> "07",  
"tags" =\> [  
[0] "\_dateparsefailure"  
],  
"dateEntree" =\> "04"  
}

---

<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:** [March 22, 2020, 4:47pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/2 "2020-03-22T16:47:55Z")

</div>

> [@Emna1](#):
>
> "date" =\> "05-03-2020"

That does not match "dd/MM/YY". Try "dd-MM-YY".

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [March 22, 2020, 4:59pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/3 "2020-03-22T16:59:04Z")

</div>

in my csv file i have column like this ;  
Date  
05.03.2020  
05.03.2020  
06.03.2020  
.....  
So i change in my file config like this : {  
match =\> ["Date", "dd.MM.yyyy"]  
target =\> "Date"  
}

=====\> i don't understand why he return in logstah this format ??  
"Date" =\> 2020-03-04T23:00:00.000Z,  
"Status" =\> "OK",  
"@timestamp" =\> 2020-03-22T16:51:00.292Z,

---

<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:** [March 22, 2020, 5:01pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/4 "2020-03-22T17:01:01Z")

</div>

> [@Emna1](#):
>
> "Date" =\> 2020-03-04T23:00:00.000Z

That's the format of a LogStash::Timestamp. It means the date filter has successfully parsed the field.

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [March 22, 2020, 5:11pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/5 "2020-03-22T17:11:27Z")

</div>

OK!! but it does not display the data in the date column in my csv file, i try this format "dd-MM-YY"  
he return the same thing? what shoud i do??

---

<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:** [March 22, 2020, 5:16pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/6 "2020-03-22T17:16:44Z")

</div>

If the field in elasticsearch is currently text, then if logstash sends a date elasticsearch will convert it to text as it indexes a document. If the field does not currently exist then elasticsearch will index it as a date. Try rolling over to a new index.

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [March 22, 2020, 5:29pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/7 "2020-03-22T17:29:59Z")

</div>

even if i create a new index it return the same thing ..!!

---

<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:** [March 22, 2020, 6:17pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/8 "2020-03-22T18:17:37Z")

</div>

Is it possible you have an [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html) in elasticsearch that forces the field to be text?

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [March 22, 2020, 7:08pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/9 "2020-03-22T19:08:43Z")

</div>

when i test in console of kibana GET /myIndex/\_mapping

"myIndex" : {  
"mappings" : {  
"properties" : {  
"@timestamp" : {  
"type" : "date"  
},  
"Date" : {  
"type" : "date"  
},  
"Status" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
....................  
so here it's change but i don't know where is the data of date in my csv file?

---

<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:** [March 22, 2020, 8:28pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/10 "2020-03-22T20:28:12Z")

</div>

OK, in the Discover pane in Kibana, if you expand an event and click on the JSON tab what does the Date field look like?

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [March 22, 2020, 9:10pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/11 "2020-03-22T21:10:35Z")

</div>

"date": "2020-03-23T23:00:00.000Z",

---

<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:** [March 22, 2020, 11:31pm UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/13 "2020-03-22T23:31:48Z")

</div>

OK, so in elasticsearch it is a date. I don't understand what problem you have. Are you saying you want to modify the source CSV file?

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [March 23, 2020, 9:57am UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/14 "2020-03-23T09:57:42Z")

</div>

thank you very much for your answer  
my problem is solved, thank you.  
just I have another question about the input file in logstash in real time, can I ask my question please,maybe you can advice me!!

---

<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 20, 2020, 9:57am UTC](https://discuss.elastic.co/t/how-to-convert-field-date-from-string-to-date/224467/15 "2020-04-20T09:57:42Z")

</div>

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