ES通过reindex修改mapping
例如此处需要将age属性由keyword 改为integer
1.查询需要修改的索引的mapping
GET test_index/_mapping
#result
{
"test_index" : {
"mappings" : {
"_doc" : {
"properties" : {
"age" : {
"type" : "keyword"
}
}
}
}
}
2. 创建与此索引相同mapping的副本索引
PUT test_index_new
{
"test_index_new" : {
"mappings" : {
"_doc" : {
"properties" : {
"age" : {
"type" : "keyword"
}
}
}
}
}
3.索引数据迁移
POST _reindex
{
"source": {
"index": "test_index"
},
"dest": {
"index": "test_index_new"
}
}
4.删除旧的索引
DELETE test_index
5.创建旧索引,并重新配置maaping
PUT test_index
{
"test_index" : {
"mappings" : {
"_doc" : {
"properties" : {
"age" : {
"type" : "integer"
}
}
}
}
}
6.将数据迁移到修改mapping后的索引上
POST _reindex
{
"source": {
"index": "test_index_new"
},
"dest": {
"index": "test_index"
}
}
7.删掉创建的新索引
新索引主要用来保存数据
DELETE test_index_new
|