在es里要修改索引字段,运气好的时候,可以用简单方案:
https://www.jianshu.com/p/fb903f4e35cf
但是大多数情况下还是要认命。思路大概是:
- 创建临时索引
- 把数据备份到临时索引
- 确认数据是否备份成功
- 删除旧索引
- 创建新索引
- 把临时索引的数据拷贝回新索引
- 删除临时索引
创建临时索引
先用GET命令获得索引的mappings和settings信息
GET xxxx
用PUT命令创建一个一样结构的临时索引
PUT xxxx_tmp20221007/
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"content": {
"type": "keyword"
},
...
}
}
}
把数据备份到临时索引
POST _reindex
{
"source": {
"index": "xxxx"
},
"dest": {
"index": "xxxx_tmp20221007"
}
}
查询数据是否拷贝成功
GET xxxx_tmp20221007/_search
删除旧索引
DELETE xxxx
创建新索引
PUT xxxx/
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"content": {
"type": "keyword"
},
...
}
}
}