Reputation: 9722
From this page: https://www.elastic.co/blog/changing-mapping-with-zero-downtime 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 https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html says:
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?
Upvotes: 0
Views: 2211
Reputation: 52368
Alternatively, you can add the mapping for a new type (or update the mapping for an existing type) later, using the /_mapping endpoint.
Update
here doesn't mean you can do whatever you want with that field, implicitly changing the type. There are very few things that you can change to an existing field. For example, one of them is described in the sub-section called "Upgrade to a multi-field".
But, if you want to change the type from string
to long
or vice-versa or change the index
from analyzed
to not_analyzed
or any other change that will potentially affect how the field content is being kept in the index itself, this is not possible.
Upvotes: 1
Reputation: 62638
You can't change mappings for existing fields. In Elasticsearch parlance, a type is a class of similar documents for which you can put an updated mapping (which adds new field mappings) but you can't change an existing mapping for a field.
For example, given a documents
type which contains mapping for title
and tags
fields, you could PUT an updated mapping for the type which adds a mapping for an author
field, but you couldn't change tags
from one type to another, or change the mapping options or whatnot.
If you want to change your field from a string to a long, you're going to need to drop the index (or the mapping for the type, which is equivalent if the index only contains the one type), create a new index with your desired mapping, and then reindex your data into it.
Upvotes: 0