在es里要修改索引字段,運(yùn)氣好的時(shí)候梳凛,可以用簡單方案:
http://www.reibang.com/p/fb903f4e35cf
但是大多數(shù)情況下還是要認(rèn)命乾蛤。思路大概是:
- 創(chuàng)建臨時(shí)索引
- 把數(shù)據(jù)備份到臨時(shí)索引
- 確認(rèn)數(shù)據(jù)是否備份成功
- 刪除舊索引
- 創(chuàng)建新索引
- 把臨時(shí)索引的數(shù)據(jù)拷貝回新索引
- 刪除臨時(shí)索引
創(chuàng)建臨時(shí)索引
先用GET命令獲得索引的mappings和settings信息
GET xxxx
用PUT命令創(chuàng)建一個(gè)一樣結(jié)構(gòu)的臨時(shí)索引
PUT xxxx_tmp20221007/
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"content": {
"type": "keyword"
},
...
}
}
}
把數(shù)據(jù)備份到臨時(shí)索引
POST _reindex
{
"source": {
"index": "xxxx"
},
"dest": {
"index": "xxxx_tmp20221007"
}
}
查詢數(shù)據(jù)是否拷貝成功
GET xxxx_tmp20221007/_search
刪除舊索引
DELETE xxxx
創(chuàng)建新索引
PUT xxxx/
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"content": {
"type": "keyword"
},
...
}
}
}