# Changing field types

**URL:** https://discuss.elastic.co/t/changing-field-types/24626
**Category:** Elasticsearch
**Created:** [June 30, 2015, 1:33pm UTC](https://discuss.elastic.co/t/changing-field-types/24626 "2015-06-30T13:33:24Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![eacoimbra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eacoimbra/32/3518_2.png) [@eacoimbra](https://discuss.elastic.co/u/eacoimbra)
#### Post date: [June 30, 2015, 1:33pm UTC](https://discuss.elastic.co/t/changing-field-types/24626/1 "2015-06-30T13:33:25Z")

</div>

Hi,

I'm new to ELK and I am testing this solution for storing logs of servers and network assets.

One of the collected logs is from an ASA-5520 and being structured through these grok patterns [https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/firewalls](https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/firewalls)

The problem is that almost all the fields have been mapped as a string and I would like some fields such as "bytes" to be converted to int and make better graphs in Kibana.

It's possible? How?

Right now I'm doing the opposite direction and reading the elasticserach documentation to understand basic concepts such as cluster, node, index, shard, replica, mapping, etc ...

Regards,  
Emerson

---

<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: [June 30, 2015, 8:58pm UTC](https://discuss.elastic.co/t/changing-field-types/24626/2 "2015-06-30T20:58:32Z")

</div>

You can use Logstash's [mutate filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) to convert the type of one or more fields from strings to integers, which will cause Elasticsearch to index those fields as integers. You can also use an Elasticsearch index template to force such a mapping by setting an explicit mapping and override ES's guesses.

---

<div class="post-metadata">

### Author: ![eacoimbra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eacoimbra/32/3518_2.png) [@eacoimbra](https://discuss.elastic.co/u/eacoimbra)
#### Post date: [July 1, 2015, 10:43am UTC](https://discuss.elastic.co/t/changing-field-types/24626/3 "2015-07-01T10:43:33Z")

</div>

If I use mutate from one point, ElasticSearch will re-index all previous instances of that field with the new type?

---

<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: [July 1, 2015, 11:50am UTC](https://discuss.elastic.co/t/changing-field-types/24626/4 "2015-07-01T11:50:21Z")

</div>

No, it only affects future messages.

---

<div class="post-metadata">

### Author: ![ilevina](https://avatars.discourse-cdn.com/v4/letter/i/85f322/32.png) [@ilevina](https://discuss.elastic.co/u/ilevina)
#### Post date: [November 6, 2015, 9:48pm UTC](https://discuss.elastic.co/t/changing-field-types/24626/5 "2015-11-06T21:48:26Z")

</div>

If used river plugin to import svc data to ElasticSearch, is there any way to convert type of string to integer? There is my mapping:  
{  
"sdkmetrics\_csv\_data": {  
"mappings": {  
"csv\_type": {  
"properties": {  
"column1": {  
"type": "string"  
},  
"column2": {  
"type": "string"  
},  
"column3": {  
"type": "string"  
},  
"imported\_at": {  
"type": "date",  
"format": "dateOptionalTime"  
}  
}  
}  
}  
}  
}

I tried to use the following to change existing type for column2 POST

{  
"csv\_type" : {  
"properties" : {  
"column2" : {"type" : "integer", "store" : "yes"}  
}  
}

generates error response:  
{  
"error": "MergeMappingException[Merge failed with failures {[mapper [column2] of different type, current\_type [string], merged\_type [integer]]}]",  
"status": 400  
}

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 7, 2015, 8:00am UTC](https://discuss.elastic.co/t/changing-field-types/24626/6 "2015-11-07T08:00:34Z")

</div>

No. You need to reindex.

---

<div class="post-metadata">

### Author: ![ilevina](https://avatars.discourse-cdn.com/v4/letter/i/85f322/32.png) [@ilevina](https://discuss.elastic.co/u/ilevina)
#### Post date: [November 9, 2015, 3:57pm UTC](https://discuss.elastic.co/t/changing-field-types/24626/7 "2015-11-09T15:57:41Z")

</div>

Thx a lot for an answer, could you please be more specific on how I could do re-index in such case. Such as, could I use Mapping API to do it ? Or?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 9, 2015, 4:09pm UTC](https://discuss.elastic.co/t/changing-field-types/24626/8 "2015-11-09T16:09:32Z")

</div>

Some ideas [here](http://david.pilato.fr/blog/2015/05/20/reindex-elasticsearch-with-logstash/).  
Some clients also have this feature IIRC.

There is a reindex plugin. I never tested it though.

---

<div class="post-metadata">

### Author: ![ilevina](https://avatars.discourse-cdn.com/v4/letter/i/85f322/32.png) [@ilevina](https://discuss.elastic.co/u/ilevina)
#### Post date: [November 9, 2015, 8:48pm UTC](https://discuss.elastic.co/t/changing-field-types/24626/9 "2015-11-09T20:48:45Z")

</div>

Thx for help. Since I was experimenting with indexing csv files with river-cvs plugin, in other words it was not critical to delete index created by river-cvs plugin. So just for those who would liketo use river-csv plugin and preserve types: Before indexing data in csv file : 1) create index using Map API, where you could specify types for each column. 2) Then use newly created index when indexing csv file with river-cvs plugin.

---

<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: [July 5, 2017, 11:39pm UTC](https://discuss.elastic.co/t/changing-field-types/24626/10 "2017-07-05T23:39:39Z")

</div>


