Dibish
Dibish

Reputation: 9303

How to update elasticsearch field type

I need to update elasticsearch field type integer to long I tried the following way and it not works

curl -XPUT 'http://localhost:9200/testwork/_mapping/message?ignore_conflicts=true' -d '
{
    "message" : {
        "properties" : {
            "status" : {"type" : "long"}
        }
    }
}
'

When tried without ignore_conflicts parameter it getting error like

{"error":"MergeMappingException[Merge failed with failures {[mapper [status] of different type, current_type [integer], merged_type [long]]}]","status":400}

But not get error while using ignore_conflicts parameter got the response like

{"acknowledged":true} 

But the type not changed for status field. Please help me to do this

Upvotes: 11

Views: 6774

Answers (1)

Olly Cruickshank
Olly Cruickshank

Reputation: 6180

It is not possible to change the data type if you have data present.

You'll have to delete your index, create the mapping with the data type you want, and re-index your data.


To re-index you will need to export and re-import your data - there are some tools (scan&scroll and bulk API) to make this easier, see reindexing your data.

An alternative is to create a new index and then use aliasing - i.e. when doing an insert write to the latest index (could use an alias with a single index in it), but when doing a query, read from an alias that includes all relevant indexes (new and old versions of the index).

Upvotes: 14

Related Questions