Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 572
Dibish Avatar asked Nov 19 '14 11:11

Dibish


1 Answers

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).

like image 95
Olly Cruickshank Avatar answered Oct 04 '22 04:10

Olly Cruickshank