# Change field type from string to integer? and how to re-index?

**URL:** <https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021>\
**Category:** Elasticsearch\
**Created:** [August 25, 2015, 2:56pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021 "2015-08-25T14:56:38Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelzoet](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@michaelzoet](https://discuss.elastic.co/u/michaelzoet)\
**Post date:** [August 25, 2015, 2:56pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/1 "2015-08-25T14:56:38Z")

</div>

Hi all Elasticsearch users,

in a newly created ELK setup I have done the mistake of not explicitly setting the type to integer (or float) on some fields.

What do I need to do in Elasticsearch (and/or Kibana) after I have setup everything correct in Logstash with the grok or mutate filter? As far as I understand I need to completely erase the existing index and create it new. Is this correct? Or is there another way to do this? Just deleting only the fields I need to change?  
What will happen if I change the type in Logstash without changing anything on the Elasticsearch index?

And which is better to use grok or mutate?

Thx in advance,  
Michael

---

<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 26, 2015, 6:12am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/2 "2015-08-26T06:12:01Z")

</div>

> As far as I understand I need to completely erase the existing index and create it new. Is this correct? Or is there another way to do this? Just deleting only the fields I need to change?

Yes, you have to reindex. You can do that with Logstash (example configs have been posted in the past) or third-party tools like es-reindex. After reindexing to a new name (e.g. the original name with an underscore appended) you can delete the original index and create an alias named like the original index that points to the new index. Thereby everything will work as before.

> What will happen if I change the type in Logstash without changing anything on the Elasticsearch index?

Then the next index that's created (the next day if you use daily indexes) will have the correct mappings.

> And which is better to use grok or mutate?

Use for what, making a field an integer or float? Using the grok filter is typically easier, but not all fields are created by that filter.

---

<div class="post-metadata">

**Author:** ![michaelzoet](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@michaelzoet](https://discuss.elastic.co/u/michaelzoet)\
**Post date:** [August 26, 2015, 7:26am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/3 "2015-08-26T07:26:25Z")

</div>

Thanks again Magnus for the answer. You really helped me a lot for this setup! At least I have plan now :-).

One last question: What problems might arise when I do not change anything in Elasticsearch and do not reindex? (Only change the values in Logstash with grok and mutate? I have daily indexes (as recommended) and at the moment I do not care about the old data. The setup will be used in production sometime next week and old data is not of any interest at the moment.

Michael

---

<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 26, 2015, 8:09am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/4 "2015-08-26T08:09:10Z")

</div>

As long as you don't attempt aggregations or range queries that span over days with both string values and integer/float values I you're going to be okay.

---

<div class="post-metadata">

**Author:** ![michaelzoet](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@michaelzoet](https://discuss.elastic.co/u/michaelzoet)\
**Post date:** [August 26, 2015, 9:29am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/5 "2015-08-26T09:29:02Z")

</div>

Thanks a lot! First I will go for the least effort and see where this goes.

---

<div class="post-metadata">

**Author:** ![Florin\_Andrei](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@Florin\_Andrei](https://discuss.elastic.co/u/Florin_Andrei)\
**Post date:** [January 22, 2016, 2:25am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/6 "2016-01-22T02:25:05Z")

</div>

So, what happened? Did the type magically change next day?

---

<div class="post-metadata">

**Author:** ![michaelzoet](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@michaelzoet](https://discuss.elastic.co/u/michaelzoet)\
**Post date:** [January 22, 2016, 6:19am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/7 "2016-01-22T06:19:18Z")

</div>

Yes and no ;-).

The type changed from the date on where I did the change. But as  
expected the older data kept it's data type. The problem with this is  
that you can not visualize any data with this correctly for this index  
field.  
As I wanted to avoid reindexing the whole data, I just changed the name  
of the index field. But this only worked because the older data was not  
important. Otherwise reindexing is a must.

---

<div class="post-metadata">

**Author:** ![mirnuj\_atom](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@mirnuj\_atom](https://discuss.elastic.co/u/mirnuj_atom)\
**Post date:** [March 17, 2016, 1:44pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/8 "2016-03-17T13:44:17Z")

</div>

Sorry for bumping an old thread but could you be so kind to explain exactly what you did to get it solved?  
I need to change one field from 'string' to 'integer' (bytes filed from apache logs) but for some reason can't. I have added 'mutate { convert =\> { "bytes" =\> "integer" } }' to an appropriate logstash conf but see no result. Also tried to create a new index wth correct values but it seems that I have to somehow change the default index (logstash-\*)...

I am fine with reindexing or/and removing all the data.  
Feeling lot here ☹

Thank you very much for any info.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [May 16, 2016, 3:18pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/9 "2016-05-16T15:18:23Z")

</div>

Hi, I also have used mutate to change an existing, indexed field from a String to a Float.

I followed this article [https://www.elastic.co/guide/en/elasticsearch/guide/current/reindex.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/reindex.html) and ran the following in the Kibana Sense plugin:

```
GET /logstash-2016.05.*/_search?scroll=1m
{
    "query": {
        "range": {
            "date": {
                "gte": "2016-05-01",
                "lt": "2016-05-16"
            }
        }
    },
    "sort": ["_doc"],
    "size": 1000
}

```

I saw the following output:

```
{
  "_scroll_id": "cXVlcnlUaGVuRmV0Y2g7ODA7NjE2Nzg3OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODAxOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzg4OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzg5OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2NzkwOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2NzkxOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2NzkyOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2NzkzOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzk0OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzk1OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzk2OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzk3OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzk4OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2Nzk5OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODAwOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODAyOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODAzOnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODA0OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODA1OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODA2OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODA3OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODA4OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODA5OnkzNU55V1Z2U015X2JERHdmVVZqN3c7NjE2ODEwOnkzNU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X2JERHdmVVZqN3c7NjE2ODY2OnkzNU55V1Z2U015X2JERHdmVVZqN3c7MDs=",
  "took": 26,
  "timed_out": false,
  "_shards": {
    "total": 80,
    "successful": 80,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

```

But the Settings link in Kibana still shows a conflict for the field which I changed from a String to a Float via Logstash's mutate filter.

Any ideas what I have done wrong/missed? Many thanks...

---

<div class="post-metadata">

**Author:** ![pickypg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pickypg/32/62409_2.png) [@pickypg](https://discuss.elastic.co/u/pickypg)\
**Post date:** [May 16, 2016, 3:32pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/10 "2016-05-16T15:32:05Z")

</div>

@Jeremy_Colton

Probably worth creating your own thread, but offhand it appears that your searched the wrong field? Logstash creates a `@timestamp` field by default, not a `date` field. Perhaps you crated the `date` field though.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [May 16, 2016, 3:38pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/11 "2016-05-16T15:38:29Z")

</div>

Why a new thread - the title is about re-indexing?

I took the example JSON from the Elastic Search article... I took your advice and changed the search field from "date" to "@timestamp" - but still no difference to my conflicted field in the Settings tab.

So I removed the search field altogether and ran:

```
GET /logstash-2016.05.*/_search?scroll=1m
{
    "sort": ["_doc"],
    "size": 1000
}

```

- no difference. Any idea? Many thanks...

---

<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:** [May 17, 2016, 6:48pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/12 "2016-05-17T18:48:03Z")

</div>

> Why a new thread - the title is about re-indexing?

That doesn't mean that this thread is suitable for _all_ questions about reindexing.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Colton](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@Jeremy\_Colton](https://discuss.elastic.co/u/Jeremy_Colton)\
**Post date:** [May 18, 2016, 8:35am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/13 "2016-05-18T08:35:08Z")

</div>

My apologies, I've created a new thread for my re-indexing issue:

> [@Re-index after changing field type from String to Float](https://discuss.elastic.co/t/re-index-after-changing-field-type-from-string-to-float/50317):
>
> Hi, I have a 'duration' field being indexed in my ES as of May 5th 2016. Logstash automatically created it as type String. A few days and a few records later I realised this problem and configured Logstash to set this field's type to Float via the mutate filter. I see in the logstash logs that the field is now being parsed as a Float. In Kibana on the settings page for my logstash-\* index, on clicking the 'refresh field list' link, i see the expected warning: Mapping conflict! A field is d…

---

<div class="post-metadata">

**Author:** ![qixiaobo](https://avatars.discourse-cdn.com/v4/letter/q/a9adbd/32.png) [@qixiaobo](https://discuss.elastic.co/u/qixiaobo)\
**Post date:** [December 20, 2016, 5:31am UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/14 "2016-12-20T05:31:29Z")

</div>

I meet the same problem now.How can I solve it?

---

<div class="post-metadata">

**Author:** ![telebh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/telebh/32/42272_2.png) [@telebh](https://discuss.elastic.co/u/telebh)\
**Post date:** [May 25, 2017, 6:17pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/15 "2017-05-25T18:17:09Z")

</div>

I have posted the same question in another thread "Number format Exception" but after read this thread i though it is related as well.

I have same issue recently. i have production index mapping where i defined "auid" as "string", then later on i found it should be "integer" so i created a new index with mapping "auid" as integer, then using reindex API to re-index data from old index to the newindex, but I am getting the exception below??

"failures" : [  
{  
"index" : "newindex",  
"type" : "author",  
"id" : "123",  
"cause" : {  
"type" : "mapper\_parsing\_exception",  
"reason" : "failed to parse [auid]",  
"caused\_by" : {  
"type" : "number\_format\_exception",  
"reason" : "For input string: "1111""  
}  
},  
"status" : 400  
},

---

<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, 10:00pm UTC](https://discuss.elastic.co/t/change-field-type-from-string-to-integer-and-how-to-re-index/28021/16 "2017-07-05T22:00:02Z")

</div>


