# Mutate filter unable to convert date to string

**URL:** <https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518>\
**Category:** Logstash\
**Created:** [August 1, 2018, 9:13am UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518 "2018-08-01T09:13:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravian100](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravian100/32/33941_2.png) [@ravian100](https://discuss.elastic.co/u/ravian100)\
**Post date:** [August 1, 2018, 9:13am UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/1 "2018-08-01T09:13:02Z")

</div>

I have searched a lot regarding this issue and now I am posting this problem.  
here is my configuration file.

input {  
file {  
path =\> "/home/Kunden2.csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}  
filter {  
csv {  
separator =\> ","  
columns =\> [  
"Kunden\_Id",  
"Kunden\_Gueltig\_Ab",  
"Kunden\_geultig\_Bis",  
"Kunden\_Vorname",  
"Kunden\_Nachname",  
"Kundenname",  
"Kunden\_Othername",  
"Kundenanschrift, Strasse und Hausnummer",  
"Kundenanschrift Postleitzahl",  
"Kunden\_Telephon",  
"Kunden\_Fax",  
"Kundenanschrift Ort",  
"Kunden\_Arzt\_Type",  
"Kunden\_Gpid",  
"IK-NR.: = Instituationskennzeichen",  
"Instituationskennzeichen\_Activeab",  
"Instituationskennzeichen\_Activebis"  
]  
}  
mutate {  
convert =\> {  
"Kunden\_Gueltig\_Ab"=\> "string"  
"Kunden\_geultig\_Bis"=\> "string"  
"Instituationskennzeichen\_Activeab"=\> "string"  
"Instituationskennzeichen\_Activebis" =\> "string"  
}  
}  
}  
output {  
elasticsearch {  
hosts =\> "[http://localhost:9200](http://localhost:9200)"  
index =\> "Kunden\_lexica2"  
}  
stdout {}  
}

I am trying to convert date into string using logstash configuration files. Data loads successfully but the data type is not changing.  
I know the other way [map date type manually] like  
PUT temp\_index2  
{  
"mappings": {  
"doc": {  
"properties": {  
"Kunden\_Id": { "type": "text" },  
"Kunden\_Gueltig\_Ab": { "type": "text" },  
"Kunden\_geultig\_Bis": { "type": "text" },  
"Kunden\_Vorname": { "type": "text" },  
"Kunden\_Nachname": { "type": "text" },  
"Kundenname": { "type": "text" },  
"Kunden\_Othername": { "type": "text" },  
"Kundenanschrift, Strasse und Hausnummer": { "type": "text" },  
"Kundenanschrift Postleitzahl": { "type": "text" },  
"Kunden\_Telephon": { "type": "text" },  
"Kunden\_Fax": { "type": "text" },  
"Kundenanschrift Ort": { "type": "text" },  
"Kunden\_Arzt\_Type": { "type": "text" },  
"Kunden\_Gpid": { "type": "text" },  
"IK-NR.: = Instituationskennzeichen": { "type": "text" },  
"Instituationskennzeichen\_Activeab": { "type": "text" },  
"Instituationskennzeichen\_Activebis": { "type": "text" }  
}  
}  
}  
}  
Kindly help me out, I want to do it by first method. Thank you in advance

---

<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:** [August 1, 2018, 9:39am UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/2 "2018-08-01T09:39:05Z")

</div>

Have you reindexed the data? Changing the data type in Logstash won't affect the mappings of an existing ES index.

---

<div class="post-metadata">

**Author:** ![ravian100](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravian100/32/33941_2.png) [@ravian100](https://discuss.elastic.co/u/ravian100)\
**Post date:** [August 1, 2018, 9:47am UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/3 "2018-08-01T09:47:08Z")

</div>

Thank you for answer. By creating manual index and then re-indexing works. But what about through logstash as I mentioned in my problem statement? I want to change data type before loading the data

---

<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:** [August 1, 2018, 11:19am UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/4 "2018-08-01T11:19:31Z")

</div>

You can certainly change the data type of a field in a Logstash event (and doing so will affect ES's auto-detection of field types), but nothing you do in Logstash can change the mappings of an existing ES index.

If ES incorrectly detects a string as a date there's nothing Logstash can do to avoid that.

---

<div class="post-metadata">

**Author:** ![ravian100](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ravian100/32/33941_2.png) [@ravian100](https://discuss.elastic.co/u/ravian100)\
**Post date:** [August 6, 2018, 3:23pm UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/5 "2018-08-06T15:23:12Z")

</div>

@magnusbaeck Can you please elaborate your answer with the help of some example i-e in my case, mentioned above in the question area. That would be great for understanding purpose.

---

<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:** [August 6, 2018, 5:47pm UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/6 "2018-08-06T17:47:38Z")

</div>

I don't understand what you're asking. You already know how to use the mutate filter to convert the data type of a field in Logstash and you know how to use the put mapping API to explicitly set the mappings of a field. What is still unclear?

---

<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:** [August 6, 2018, 6:33pm UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/7 "2018-08-06T18:33:05Z")

</div>

If logstash sends a field that does not exist in the index with a string value such as "2018-08-06T17:18:50.558Z" to elasticsearch, then unless there is a template that tells it not to, elasticsearch will convert that to a date. You cannot change that behaviour in logstash.

So you can use a template, or you can force the field to exist as a string by ingesting a dummy record that does not look like a date.

---

<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:** [September 3, 2018, 6:33pm UTC](https://discuss.elastic.co/t/mutate-filter-unable-to-convert-date-to-string/142518/8 "2018-09-03T18:33:23Z")

</div>

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