由于ES不能像关系型数据库直接修改类型,所以要借助中间索引来完成
1、创建中间索引(字段维护正确的)
put: https://localhost/track_bak
{
"settings": {
"index": {
"number_of_shards": "3",
"number_of_replicas": "1",
"max_result_window": "10000000"
},
"analysis": {
"analyzer": {
"sanalyzer": {
"tokenizer": "standard"
}
},
"normalizer": {
"lowercase": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"Id": {
"type": "keyword",
"normalizer": "lowercase"
},
"TrackingNumber": {
"type": "keyword",
"normalizer": "lowercase"
},
"ForwarderByID": {
"type": "keyword",
"normalizer": "lowercase"
},
"OrderId": {
"type": "keyword",
"normalizer": "lowercase"
},
"OrderTypeId": {
"type": "short"
},
"OrderTypeStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"PackageId": {
"type": "keyword",
"normalizer": "lowercase"
},
"WarehouseId": {
"type": "keyword",
"normalizer": "lowercase"
},
"PlatformId": {
"type": "keyword"
},
"PlatformStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"AccountId": {
"type": "short"
},
"AccountStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"InputUserId": {
"type": "keyword",
"normalizer": "lowercase"
},
"InputUserStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"StoreManagerId": {
"type": "keyword",
"normalizer": "lowercase"
},
"StoreManagerStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"CountryId": {
"type": "keyword",
"normalizer": "lowercase"
},
"CountryStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"UploadState": {
"type": "short"
},
"UploadStateStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"LastEvent": {
"type": "keyword",
"normalizer": "lowercase"
},
"LastUpdateTime": {
"type": "date"
},
"NoUpdateTime": {
"type": "double"
},
"LogisticsState": {
"type": "keyword",
"normalizer": "lowercase"
},
"LogisticsStateStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"LogisticId": {
"type": "keyword",
"normalizer": "lowercase"
},
"LogisticWayId": {
"type": "keyword",
"normalizer": "lowercase"
},
"SendTime": {
"type": "date"
},
"ItemReceived": {
"type": "keyword",
"normalizer": "lowercase"
},
"ItemDispatched": {
"type": "keyword",
"normalizer": "lowercase"
},
"DepartfromAirport": {
"type": "keyword",
"normalizer": "lowercase"
},
"ArrivalfromAbroad": {
"type": "keyword",
"normalizer": "lowercase"
},
"CustomsClearance": {
"type": "keyword",
"normalizer": "lowercase"
},
"DestinationArrived": {
"type": "keyword",
"normalizer": "lowercase"
},
"Remark": {
"type": "keyword",
"normalizer": "lowercase"
},
"TrackCode": {
"type": "keyword",
"normalizer": "lowercase"
},
"Createon": {
"type": "date"
},
"LastUpdOn": {
"type": "date"
},
"DepartureNO": {
"type": "keyword",
"normalizer": "lowercase"
}
}
}
}
2、重建索引(把老索引同步到备份索引)
post: https://localhost/_reindex
{
"source": {
"index": "track"
},
"dest": {
"index": "track_bak"
}
}
3、删掉有问题的老索引
DELETE track
4、创建同名老索引(也可以将新索引重命名为老索引,实践中遇到问题所以采用重建方式)
重命名方式(实践中碰到异常没来得及展开研究)
put: https://localhost/_aliases
{
"actions": [
{
"add": {
"index": "track_bak",
"alias": "track"
}
}
]
}
采取重新创建方式
put: https://localhost/track
{
"settings": {
"index": {
"number_of_shards": "3",
"number_of_replicas": "1",
"max_result_window": "10000000"
},
"analysis": {
"analyzer": {
"sanalyzer": {
"tokenizer": "standard"
}
},
"normalizer": {
"lowercase": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"Id": {
"type": "keyword",
"normalizer": "lowercase"
},
"TrackingNumber": {
"type": "keyword",
"normalizer": "lowercase"
},
"ForwarderByID": {
"type": "keyword",
"normalizer": "lowercase"
},
"OrderId": {
"type": "keyword",
"normalizer": "lowercase"
},
"OrderTypeId": {
"type": "short"
},
"OrderTypeStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"PackageId": {
"type": "keyword",
"normalizer": "lowercase"
},
"WarehouseId": {
"type": "keyword",
"normalizer": "lowercase"
},
"PlatformId": {
"type": "keyword"
},
"PlatformStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"AccountId": {
"type": "short"
},
"AccountStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"InputUserId": {
"type": "keyword",
"normalizer": "lowercase"
},
"InputUserStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"StoreManagerId": {
"type": "keyword",
"normalizer": "lowercase"
},
"StoreManagerStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"CountryId": {
"type": "keyword",
"normalizer": "lowercase"
},
"CountryStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"UploadState": {
"type": "short"
},
"UploadStateStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"LastEvent": {
"type": "keyword",
"normalizer": "lowercase"
},
"LastUpdateTime": {
"type": "date"
},
"NoUpdateTime": {
"type": "double"
},
"LogisticsState": {
"type": "keyword",
"normalizer": "lowercase"
},
"LogisticsStateStr": {
"type": "keyword",
"normalizer": "lowercase"
},
"LogisticId": {
"type": "keyword",
"normalizer": "lowercase"
},
"LogisticWayId": {
"type": "keyword",
"normalizer": "lowercase"
},
"SendTime": {
"type": "date"
},
"ItemReceived": {
"type": "keyword",
"normalizer": "lowercase"
},
"ItemDispatched": {
"type": "keyword",
"normalizer": "lowercase"
},
"DepartfromAirport": {
"type": "keyword",
"normalizer": "lowercase"
},
"ArrivalfromAbroad": {
"type": "keyword",
"normalizer": "lowercase"
},
"CustomsClearance": {
"type": "keyword",
"normalizer": "lowercase"
},
"DestinationArrived": {
"type": "keyword",
"normalizer": "lowercase"
},
"Remark": {
"type": "keyword",
"normalizer": "lowercase"
},
"TrackCode": {
"type": "keyword",
"normalizer": "lowercase"
},
"Createon": {
"type": "date"
},
"LastUpdOn": {
"type": "date"
},
"DepartureNO": {
"type": "keyword",
"normalizer": "lowercase"
}
}
}
}
5、重建索引(把要备份索引同步到新索引)
post: https://localhost/_reindex
{
"source": {
"index": "track_bak"
},
"dest": {
"index": "track"
}
}
6、确认数据已全部同步之后,删除备份索引
DELETE track_bak
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!