参考:https://blog.csdn.net/weixin_41228362/article/details/107382647
概述
首先说明es中索引的字段类型是不可修改的,只能是重新创建一个索引并设置好mapping,然后再将老索引的数据复制过去。
操作步骤
1、创建索引,并指定mapping
PUT /web-log
{
"mappings" : {
"properties" : {
"classMethod" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"consumeTime" : {
"type" : "long"
},
"consumeTimeType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"date" : {
"type" : "date",
"format": "yyyy-M-d"
},
"day" : {
"type" : "long"
},
"hour" : {
"type" : "long"
},
"ip" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"minute" : {
"type" : "long"
},
"month" : {
"type" : "long"
},
"requestArgs" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"requestId" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"requestMethod" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"second" : {
"type" : "long"
},
"threadID" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"timestamp" : {
"type" : "long"
},
"userName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"year" : {
"type" : "long"
}
}
}
}
- 将老的索引中的数据复制到新的索引中:
POST _reindex
{
"source": {
"index": "web_log"
},
"dest": {
"index": "web-log"
}
}
最后成功了