由于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
标签:lowercase,normalizer,keyword,索引,track,修改,Elasticsearch,类型,type
From: https://www.cnblogs.com/BOSET/p/17468299.html