es重建字段类型_es之重建索引

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": {}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值