单页网站赚钱,七牛镜像存储wordpress,怎做网站转app,网站后台管理功能Elasticsearch 重建索引 数据迁移 处理流程创建临时索引数据迁移重建索引写在最后 大家都知道#xff0c;es的索引创建完成之后就不可以再修改了#xff0c;包括你想更改字段属性或者是分词方式等。那么随着业务数据量的发展#xff0c;可能会出现需要修改索引#xff0c;或… Elasticsearch 重建索引 数据迁移 处理流程创建临时索引数据迁移重建索引写在最后 大家都知道es的索引创建完成之后就不可以再修改了包括你想更改字段属性或者是分词方式等。那么随着业务数据量的发展可能会出现需要修改索引或者说叫做重建索引的情况那么这个时候应该怎么操作呢本文主要就这个问题进行讨论处理。 
处理流程 
整体的重建索引的处理流程就是先创建一个临时索引将原始索引中的数据迁移到临时索引然后再删除原始索引重新创建原始索引后在将临时索引中的数据迁回到重建索引从而完成索引的重建操作。 
创建临时索引 
在创建索引之前我们先看一下原始的 es 索引结构在 kibana 开发工具命令行页面执行命令 
GET crm_meiqia_conversation/_mapping这里我需要将字段 convId 的字段类型 改为 text 那么这个时候我就需要创建一个临时索引 crm_meiqia_conversation_tmp 将字段 convId 的字段类型改为 text 原始 convId 属性如下图  整个执行命令代码如下 
PUT /crm_meiqia_conversation_tmp
{mappings : {meiqiaConversation : {properties : {convId : {type : text},enterpriseId : {type : long},devClientId : {type : text},pageFromUrl : {type : text},pageLandUrl : {type : text},pageLandTitle : {type : text},pageConvUrl : {type : text},pageConvTitle : {type : text},searchEngineName : {type : text},searchEngineKw : {type : text},visitorIp : {type : text},visitorLocation : {type : text},visitorOs : {type : text},visitorBrowser : {type : text},visitorTags : {type : text},clientId : {type : long},agentAccount : {type : text},agentName : {type : text},agentId : {type : text},agentNickName : {type : text},groupId : {type : long},groupName : {type : text},convStartTm : {type : long},convStartDate : {type : date},convEndTm : {type : long},convEndDate : {type : date},convFirstRespWaitInSecs : {type : long},convAgentMsgCount : {type : long},convVisitorMsgCount : {type : long},convQualityGrade : {type : text},convLeads : {type : text},commentLevel : {type : long},commentContent : {type : text},platform : {type : text},summaryContent : {type : text},summaryUpdateAt : {type : text},sourceType : {type : text},sourceField : {type : text},agentRespDuration : {type : long},effective : {type : text},missed : {type : text},converseDuration : {type : long},appName : {type : text},mainChannel : {type : text},mainChannelName : {type : text},subChannel : {type : text},subChannelName : {type : text},searchEngine : {type : text},clientInfo : {properties : {address : {type : text},age : {type : long},channelName : {type : text},comment : {type : text},contact : {type : text},convId : {type : long},email : {type : text},enterpriseId : {type : long},followSource : {type : text},gender : {type : text},infoId : {type : long},jijiaoCity : {type : text},jijiaoDistrict : {type : text},jijiaoLevel : {type : text},jijiaoProvince : {type : text},mTrackId : {type : text},name : {type : text},openid : {type : text},qq : {type : text},sourceName : {type : text},tel : {type : text},trackId : {type : text},uid : {type : text},vid : {type : text},visitorName : {type : text},weibo : {type : text},weixin : {type : text},appChannel : {type : text}}},convContent : {properties : {contentId : {type : long},convId : {type : long},convFrom : {type : text},timestamp : {type : long},content : {type : text,analyzer:standard},remoteContent : {type : text},convType : {type : text}}},convTag : {properties : {tagId : {type : long},convId : {type : long},level : {type : long},value : {type : text}}}}}},settings : {number_of_shards:2, number_of_replicas : 1,refresh_interval:1s}
}在 kibana 工具页面点击执行按钮  这里可以看到执行命令报错 400 根据提示信息来看 说明当前 es 中已经存在索引 crm_meiqia_conversation_tmp 那么执行删除索引命令删除后再执行刚才创建临时索引命令 
DELETE /crm_meiqia_conversation_tmp再次执行创建临时索引命令执行成功  
数据迁移 
临时索引创建完成之后我们就可以将原始索引中的数据先迁移到临时索引中通过 ES 提供了 _reindex 这个API 进行数据复制迁移执行命令 
POST _reindex
{  source: {  index: crm_meiqia_conversation,size:500},  dest: {  index: crm_meiqia_conversation_tmp  }
}或者 异步迁移数据 
POST _reindex?wait_for_completionfalse
{  source: {  index: crm_meiqia_conversation,size:500},  dest: {  index: crm_meiqia_conversation_tmp  }}其中source 对应的是原始索引dest 对应的是新建的临时索引参数 size 表示每次执行的数据量为500 条循环执行直到数据迁移复制结束。默认情况下 _reindex 使用 1000 进行批量操作迁移成功如图  这个时候我们再来看一下原始索引中数据总数 crm_meiqia_conversation 与临时索引 crm_meiqia_conversation_tmp 中数据总数是否一致执行命令 
GET crm_meiqia_conversation/_count
GET crm_meiqia_conversation_tmp/_count执行结果如图   那么这样就完成了数据从原始索引迁移复制到临时索引的操作。 
重建索引 
这个时候就需要执行命令删除原始索引 crm_meiqia_conversation 然后按照临时索引的 创建语句 创建新的索引最后再将临时索引中的数据 迁移复制到 新建的原始索引中去执行命令 
# 删除原始索引
DELETE /crm_meiqia_conversation
# 创建更改字段后的新的原始索引 
PUT /crm_meiqia_conversation
{mappings : {meiqiaConversation : {properties : {convId : {type : text},enterpriseId : {type : long},devClientId : {type : text},pageFromUrl : {type : text},pageLandUrl : {type : text},pageLandTitle : {type : text},pageConvUrl : {type : text},pageConvTitle : {type : text},searchEngineName : {type : text},searchEngineKw : {type : text},visitorIp : {type : text},visitorLocation : {type : text},visitorOs : {type : text},visitorBrowser : {type : text},visitorTags : {type : text},clientId : {type : long},agentAccount : {type : text},agentName : {type : text},agentId : {type : text},agentNickName : {type : text},groupId : {type : long},groupName : {type : text},convStartTm : {type : long},convStartDate : {type : date},convEndTm : {type : long},convEndDate : {type : date},convFirstRespWaitInSecs : {type : long},convAgentMsgCount : {type : long},convVisitorMsgCount : {type : long},convQualityGrade : {type : text},convLeads : {type : text},commentLevel : {type : long},commentContent : {type : text},platform : {type : text},summaryContent : {type : text},summaryUpdateAt : {type : text},sourceType : {type : text},sourceField : {type : text},agentRespDuration : {type : long},effective : {type : text},missed : {type : text},converseDuration : {type : long},appName : {type : text},mainChannel : {type : text},mainChannelName : {type : text},subChannel : {type : text},subChannelName : {type : text},searchEngine : {type : text},clientInfo : {properties : {address : {type : text},age : {type : long},channelName : {type : text},comment : {type : text},contact : {type : text},convId : {type : long},email : {type : text},enterpriseId : {type : long},followSource : {type : text},gender : {type : text},infoId : {type : long},jijiaoCity : {type : text},jijiaoDistrict : {type : text},jijiaoLevel : {type : text},jijiaoProvince : {type : text},mTrackId : {type : text},name : {type : text},openid : {type : text},qq : {type : text},sourceName : {type : text},tel : {type : text},trackId : {type : text},uid : {type : text},vid : {type : text},visitorName : {type : text},weibo : {type : text},weixin : {type : text},appChannel : {type : text}}},convContent : {properties : {contentId : {type : long},convId : {type : long},convFrom : {type : text},timestamp : {type : long},content : {type : text,analyzer:standard},remoteContent : {type : text},convType : {type : text}}},convTag : {properties : {tagId : {type : long},convId : {type : long},level : {type : long},value : {type : text}}}}}},settings : {number_of_shards:2, number_of_replicas : 1,refresh_interval:1s}
}
# 迁移复制数据 临时索引》》》新的原始索引
POST _reindex
{  source: {  index: crm_meiqia_conversation_tmp,size:500},  dest: {  index: crm_meiqia_conversation  }
}最后执行成功后完成本次关于 索引 crm_meiqia_conversation 的更改字段属性 的操作  
写在最后 
其实对于 es 更改索引字段的操作确实比较费劲需要先创建临时索引转移复制数据后删除原始索引再创建新的索引并把临时索引的数据再迁移回新的索引中。所以在创建 es 索引之处就需要综合考量将字段的属性设计以及索引结构设计做到准确防止后续出现这样的情况比较费劲。另外如果待迁移索引的数据量比较大的话来回迁移数据除了耗时以外还会需要一个较大的磁盘空间才能完成操作不然会报磁盘不足的错误提示的。 文章转载自: http://www.morning.kzpy.cn.gov.cn.kzpy.cn http://www.morning.kbyp.cn.gov.cn.kbyp.cn http://www.morning.ktnt.cn.gov.cn.ktnt.cn http://www.morning.nlrxh.cn.gov.cn.nlrxh.cn http://www.morning.tsmxh.cn.gov.cn.tsmxh.cn http://www.morning.bnwlh.cn.gov.cn.bnwlh.cn http://www.morning.ldgqh.cn.gov.cn.ldgqh.cn http://www.morning.qwpyf.cn.gov.cn.qwpyf.cn http://www.morning.fdhwh.cn.gov.cn.fdhwh.cn http://www.morning.sgpny.cn.gov.cn.sgpny.cn http://www.morning.tpqrc.cn.gov.cn.tpqrc.cn http://www.morning.jrwbl.cn.gov.cn.jrwbl.cn http://www.morning.llqch.cn.gov.cn.llqch.cn http://www.morning.fktlr.cn.gov.cn.fktlr.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.tkflb.cn.gov.cn.tkflb.cn http://www.morning.fnhxp.cn.gov.cn.fnhxp.cn http://www.morning.rfkyb.cn.gov.cn.rfkyb.cn http://www.morning.sgpny.cn.gov.cn.sgpny.cn http://www.morning.sbqrm.cn.gov.cn.sbqrm.cn http://www.morning.rdbj.cn.gov.cn.rdbj.cn http://www.morning.gzttoyp.com.gov.cn.gzttoyp.com http://www.morning.jlnlr.cn.gov.cn.jlnlr.cn http://www.morning.nrxsl.cn.gov.cn.nrxsl.cn http://www.morning.xhddb.cn.gov.cn.xhddb.cn http://www.morning.pzpj.cn.gov.cn.pzpj.cn http://www.morning.mm27.cn.gov.cn.mm27.cn http://www.morning.lrjtx.cn.gov.cn.lrjtx.cn http://www.morning.zxcny.cn.gov.cn.zxcny.cn http://www.morning.nlkjq.cn.gov.cn.nlkjq.cn http://www.morning.hxpsp.cn.gov.cn.hxpsp.cn http://www.morning.lfjmp.cn.gov.cn.lfjmp.cn http://www.morning.qddtd.cn.gov.cn.qddtd.cn http://www.morning.hdlhh.cn.gov.cn.hdlhh.cn http://www.morning.mzbyl.cn.gov.cn.mzbyl.cn http://www.morning.kpxky.cn.gov.cn.kpxky.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.ytrbq.cn.gov.cn.ytrbq.cn http://www.morning.byxs.cn.gov.cn.byxs.cn http://www.morning.xpqsk.cn.gov.cn.xpqsk.cn http://www.morning.ltfnl.cn.gov.cn.ltfnl.cn http://www.morning.tqgx.cn.gov.cn.tqgx.cn http://www.morning.ldsgm.cn.gov.cn.ldsgm.cn http://www.morning.mwmtk.cn.gov.cn.mwmtk.cn http://www.morning.qgtfl.cn.gov.cn.qgtfl.cn http://www.morning.ntzfj.cn.gov.cn.ntzfj.cn http://www.morning.glpxx.cn.gov.cn.glpxx.cn http://www.morning.rgnp.cn.gov.cn.rgnp.cn http://www.morning.qbmpb.cn.gov.cn.qbmpb.cn http://www.morning.wpqwk.cn.gov.cn.wpqwk.cn http://www.morning.rhpy.cn.gov.cn.rhpy.cn http://www.morning.wrkcw.cn.gov.cn.wrkcw.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.rrpsw.cn.gov.cn.rrpsw.cn http://www.morning.mwcqz.cn.gov.cn.mwcqz.cn http://www.morning.fqcdh.cn.gov.cn.fqcdh.cn http://www.morning.mfnsn.cn.gov.cn.mfnsn.cn http://www.morning.csdgt.cn.gov.cn.csdgt.cn http://www.morning.hbxnb.cn.gov.cn.hbxnb.cn http://www.morning.nzmhk.cn.gov.cn.nzmhk.cn http://www.morning.hmtft.cn.gov.cn.hmtft.cn http://www.morning.gllhx.cn.gov.cn.gllhx.cn http://www.morning.kwyq.cn.gov.cn.kwyq.cn http://www.morning.lztrt.cn.gov.cn.lztrt.cn http://www.morning.jghty.cn.gov.cn.jghty.cn http://www.morning.bxsgl.cn.gov.cn.bxsgl.cn http://www.morning.qykxj.cn.gov.cn.qykxj.cn http://www.morning.mdwb.cn.gov.cn.mdwb.cn http://www.morning.qprtm.cn.gov.cn.qprtm.cn http://www.morning.hpprx.cn.gov.cn.hpprx.cn http://www.morning.wjndl.cn.gov.cn.wjndl.cn http://www.morning.tsqrc.cn.gov.cn.tsqrc.cn http://www.morning.fnfxp.cn.gov.cn.fnfxp.cn http://www.morning.kwqwp.cn.gov.cn.kwqwp.cn http://www.morning.bwmm.cn.gov.cn.bwmm.cn http://www.morning.gbjxj.cn.gov.cn.gbjxj.cn http://www.morning.mzhh.cn.gov.cn.mzhh.cn http://www.morning.fwrr.cn.gov.cn.fwrr.cn http://www.morning.tcxzn.cn.gov.cn.tcxzn.cn http://www.morning.bkjhx.cn.gov.cn.bkjhx.cn