Views: 211
In Elasticsearch you can't change the type of a field once the data indexed. So there is no straight way to so this in Elasticsearch. You need to follow the below steps to achieve this.
- create temp index
- put the mapping for the field with the type you want in temp index
- re-index data from source index to temp index
- drop the actual index
- create the actual index
- Put the mapping
- re-index data from temp index to actual index
- drop temp index
Following are the calls you need to make for the above points. For example, I am taking the index name as 'users', type as 'doc' and changing the field 'location' from String to geo_point
1. create temp index
PUT users_temp
2. put the mapping for the field with the type you want in temp index
PUT users_temp/_mapping/doc
{
"properties": {
"location": {
"type": "geo_point"
}
}
}
3. re-index data from source index to temp index
POST _reindex
{
"source": {
"index": "users"
},
"dest": {
"index": "users_temp"
}
}
4. drop the actual index
DELETE /users
5. create the actual index
PUT users
6. Put the mapping
PUT users/_mapping/doc
{
"properties": {
"location": {
"type": "geo_point"
}
}
}
7. re-index data from temp index to actual index
POST _reindex
{
"source": {
"index": "users_temp"
},
"dest": {
"index": "users"
}
}
8. drop temp index
DELETE /users_temp
On By
d20160501
Top Tutorials
492.5K
31.9K
21.7K
18.7K
18.6K
6.7K
6.6K
4.9K
3.3K
3.1K
Top Questions
18.6K
14.5K
8.3K
6.5K
6.1K
5.7K
4.8K
4.8K
4.3K
3.9K
Top Articles
1.9K
1.6K
944
Top Blogs
792
778
52
Top News
750
683
669
397
381
381