# 1. 创建一个中间索引
#创建索引
PUT region_user_request_record2020_07_1/
# 创建Mapping
POST region_user_request_record2020_07_1/main/_mapping
{
"main": {
"properties": {
"body": {
"type": "text"
},
"createTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"env": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"ip": {
"type": "keyword"
},
"method": {
"type": "keyword"
},
"params": {
"type": "keyword"
},
"requestTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"systemType": {
"type": "keyword"
},
"url": {
"type": "keyword"
},
"userId": {
"type": "integer"
}
}
}
}
# 2. 向中间索引备份源索引的数据
POST _reindex
{
"source": {
"index": "region_user_request_record2020_07"
},
"dest": {
"index": "region_user_request_record2020_07_1"
}
}
# 3.查询确认数据是否copy过去
GET /region_user_request_record2020_07/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"systemType": {
"value": "domain_ZJ"
}
}
}
]
}
},
"sort": [
{
"requestTime": {
"order": "desc"
}
}
]
}
GET /region_user_request_record2020_07_1/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"systemType": {
"value": "domain_ZJ"
}
}
}
]
}
},
"sort": [
{
"requestTime": {
"order": "desc"
}
}
]
}
# 4.删除有问题的索引
# 删除有问题的索引
DELETE region_user_request_record2020_07
# 5.重新创建同名的索引(★字段类型修改正确★)
#创建索引
PUT region_user_request_record2020_07/
# 创建Mapping
POST region_user_request_record2020_07/main/_mapping
{
"main": {
"properties": {
"body": {
"type": "text"
},
"createTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"env": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"ip": {
"type": "keyword"
},
"method": {
"type": "keyword"
},
"params": {
"type": "keyword"
},
"requestTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"systemType": {
"type": "keyword"
},
"url": {
"type": "keyword"
},
"userId": {
"type": "integer"
}
}
}
}
# 6. 从中间索引还原到源索引的数据
# 重建索引
POST _reindex
{
"source": {
"index": "region_user_request_record2020_07_1"
},
"dest": {
"index": "region_user_request_record2020_07"
}
}
# 7. 删除中间索引
DELETE region_user_request_record2020_07_1
# 8.给索引加别名
PUT /user_request_record_trip_1/_alias/user_request_record_trip