# ElasticSearch修改Mapping
首先我们要知道的是:
- 索引mapping一旦建好,就不支持修改了(有几种特例是可以修改的),同时也不支持删除其中字段,除非 reindex
- 你是可以随意增加字段的
下面一起看一下重建步骤吧
# 重建
# 首先看一下要重建的索引
# 查看所有索引
GET /_cat/indices?v
# 查看某个索引的详细信息
GET /gkims_recruitment_index/_mapping
1
2
3
4
5
2
3
4
5
# 建立新的索引和映射
# 建立新索引
PUT /gkims_recruitment_index111
# 为新索引建立新mapping
PUT /gkims_recruitment_index111/_mapping
{
"properties" : {
"age" : {
"type" : "long"
}
}
...............
...............
...............
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 迁移数据到新索引
# 使用reindex api将旧索引数据导入新索引
POST _reindex
{
"source": {
"index": "gkims_recruitment_index"
},
"dest": {
"index": "gkims_recruitment_index111"
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 删除旧索引
# 删除旧索引
DELETE /gkims_recruitment_index
1
2
2
# 索引名称还原
一般情况下索引名称不是随便能改的, 为了索引名称的还原,我们按照上面新建新索引的步骤再走一遍,建立旧索引,最后删除新索引即可。
还有一种做法就是给新索引取老索引的别名
POST /_aliases { "actions": [ { "add": { "index": "gkims_recruitment_index_111", "alias": "gkims_recruitment_index" }} ] }
1
2
3
4
5
6
7
8
9
特例: 文档1 (opens new window) 文档2 (opens new window) 文档3 (opens new window)