# Change field type of index-pattern from date to number

**URL:** <https://discuss.elastic.co/t/change-field-type-of-index-pattern-from-date-to-number/223311>\
**Category:** Logstash\
**Tags:** elastic-stack-monitoring\
**Created:** [March 12, 2020, 10:33am UTC](https://discuss.elastic.co/t/change-field-type-of-index-pattern-from-date-to-number/223311 "2020-03-12T10:33:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mattness](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattness/32/52975_2.png) [@Mattness](https://discuss.elastic.co/u/Mattness)\
**Post date:** [March 12, 2020, 10:33am UTC](https://discuss.elastic.co/t/change-field-type-of-index-pattern-from-date-to-number/223311/1 "2020-03-12T10:33:53Z")

</div>

Hello,

I connected Logstash to my db and it indexes certain number fields that describe a duration as dates.

I tried to just add another field-type in the created pattern with this API-call:

PUT /myindex-2020.03.10/\_mapping  
''{  
"properties": {  
"duration": {  
"type": "date",  
"fields": {  
"raw": {  
"type": "long"  
}  
}  
}  
}  
}''

this worked, but the field is not being filled with anything. I - if possible at all - do not want to delete my index because it functions as the default-pattern for some visualizations I've created.

I've also tried to use the "dissect" filter-plugin:

filter {  
dissect {  
convert\_datatype =\> {  
"duration" =\> "float"  
}  
}  
}

This resulted in a warning saying:

[org.logstash.dissect.Dissector][main] Dissector datatype conversion, value cannot be coerced, field: duration, value: 2020-03-12T00:00:00.218Z

The weird thing is that the DB-field does not contain the YYYYMMDD part .... logstash seems to add this itself.

Also when using the "mutate"-plugin the conversion works but the field is still a date. This reults in completely wrong data.

filter {  
mutate {  
convert =\> {  
"duration" =\> "integer"  
}  
}  
}

results in 00:00:00.0156265 being converted to Jan 19, 1970 @ 08:59:31.200

Regards

---

<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 9, 2020, 10:33am UTC](https://discuss.elastic.co/t/change-field-type-of-index-pattern-from-date-to-number/223311/2 "2020-04-09T10:33:58Z")

</div>

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