[Elasticsearch] ES修改字段类型

参考: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"
       }
     }
   }
 }
  1. 将老的索引中的数据复制到新的索引中:
POST _reindex
{
 "source": {
   "index": "web_log"
 },
 "dest": {
   "index": "web-log"
 }
}

最后成功了

在这里插入图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值