Trying to understand how to update a mapping without requiring a complete rebuild of the index?

(Patrick Collins) #1


From this page:, it states:

I don't care about old data
What if you want to change the datatype for a single field, and you don't care about the fact that the old data is not searchable? In this case, you have a few options:

Delete the mapping
If you delete the mapping for a specific type, then you can use the put_mapping API. to create a new mapping for that type in the existing index.


My situation is, I have a column that was a string, and I want to change it to a long... According to that document, it sounds like I should just be able to do:

curl -X DELETE localhost:9200/my_index/_mapping/property_to_change

and then do

curl -XPUT 'http://localhost:9200/my_index/_mapping/property_to_change' -d '
    "my_index" : {
        "properties" : {
            "property_to_change" : {"type" : "long", "store" : true }

Am I misunderstanding this? Do I really have to go through the trouble of creating an alias? is there not a simple way I can just change this one property's type?

I find the documentation regarding this topic high confusing and contradictory.. for example this page:


You can specify the mapping for a type when you first create an index. Alternatively, you can add the mapping for a new type (or update the mapping for an existing type) later, using the /_mapping endpoint.

Which sounds like -- ok cool. that's exactly what I want to do.

But then the next paragraph says:

Although you can add to an existing mapping, you can’t change it. If a field already exists in the mapping, the data from that field probably has already been indexed. If you were to change the field mapping, the already indexed data would be wrong and would not be properly searchable.

I thought it just said you can update the mapping? now it says you can't change it? Sooo confused.

Can anyone please shed some light on this?

Thank you.

(Mark Walkom) #2

You can update - ie add a new field - but you cannot change - ie alter a string field to an integer. That's a subtle difference between the words.

The reason you add an alias is that if you need to change an existing field, you can create a new index with the new mapping, reindex the data into the new index, and then switch the alias over to it and remove the old index.

(system) #3