1.為什么需要重建索引
舉個例子,如果一個字段是text類型,如果想修改為Long類型,是不能直接修改的。
在重建的過程中,需要有別名的參與。
2.操作步驟
對當前的索引新建一個別名
新建一個新的索引,同步結構
同步數據
給新的索引見一個別名
刪除老的索引的別名
刪除老的索引
二:操作步驟詳解
1.對當前的索引添加別名
POST /_aliases
{
"actions": [
{
"add": {
"index": "nba",
"alias": "nba_lastest"
}
}
]
}
2.新增⼀個索引(⽐如修改字段類型,jerseyNo改成keyword類型)
PUT /nba_20200202
{
"mappings": {
"properties": {
"age" : {
"type" : "integer"
},
"birthDay" : {
"type" : "date"
},
"birthDayStr" : {
"type" : "keyword"
},
"code" : {
"type" : "text"
},
"country" : {
"type" : "text"
},
"countryEn" : {
"type" : "text"
},
"displayAffiliation" : {
"type" : "text"
},
"displayName" : {
"type" : "text"
},
"displayNameEn" : {
"type" : "text"
},
"draft" : {
"type" : "long"
},
"heightValue" : {
"type" : "float"
},
"jerseyNo" : {
"type" : "keyword"
},
"playYear" : {
"type" : "long"
},
"playerId" : {
"type" : "keyword"
},
"position" : {
"type" : "text"
},
"schoolType" : {
"type" : "text"
},
"teamCity" : {
"type" : "text"
},
"teamCityEn" : {
"type" : "text"
},
"teamConference" : {
"type" : "keyword"
},
"teamConferenceEn" : {
"type" : "keyword"
},
"teamName" : {
"type" : "keyword"
},
"teamNameEn" : {
"type" : "keyword"
},
"weight" : {
"type" : "text"
}
}
}
}
3.給新的索引,同步數據
添加的參數,是異步執行的意思
POST /_reindex?wait_for_completion=false
{
"source": {
"index": "nba"
},
"dest": {
"index": "nba_20200202"
}
}
效果:
{
"task" : "O9L9cZRfQwWqC2UVUaxMaQ:18594274"
}
4.替換別名
POST /_aliases
{
"actions": [
{
"add": {
"index": "nba_20200202",
"alias": "nba_lastest"
}
},
{
"remove": {
"index": "nba",
"alias": "nba_lastest"
}
}
]
}
5.刪除舊的索引
其實,這里不刪除也行,但是會占用一些資源
DELETE /nba
6.進行驗證
GET /nba_lastest/_search
{
"query": {
"match_all": {}
}
}
