当前位置: 首页 > news >正文

Elasticsearch 重建索引 数据迁移

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_completion=false
{  "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 索引之处就需要综合考量,将字段的属性设计以及索引结构设计做到准确,防止后续出现这样的情况比较费劲。另外如果待迁移索引的数据量比较大的话,来回迁移数据除了耗时以外,还会需要一个较大的磁盘空间才能完成操作,不然会报磁盘不足的错误提示的。

相关文章:

Elasticsearch 重建索引 数据迁移

Elasticsearch 重建索引 数据迁移 处理流程创建临时索引数据迁移重建索引写在最后 大家都知道,es的索引创建完成之后就不可以再修改了,包括你想更改字段属性或者是分词方式等。那么随着业务数据量的发展,可能会出现需要修改索引,或…...

2411rust,异步函数

原文 Rust异步工作组很高兴地宣布,在实现在特征中使用异步 fn的目标方面取得了重大进度.将在下周发布稳定的Rust1.75版,会包括特征中支持impl Trait注解和async fn. 稳定化 自从RFC#1522在Rust1.26中稳定下来以来,Rust就允许用户按函数的返回类型(一般叫"RPIT")编…...

前端网络性能优化问题

DNS预解析 DNS 解析也是需要时间的&#xff0c;可以通过预解析的⽅式来预先获得域名所对应的 IP。 <link rel"dns-prefetch" href"//abcd.cn"> 缓存 强缓存 在缓存期间不需要请求&#xff0c; state code 为 200 可以通过两种响应头实现&#…...

优选算法——双指针

前言 本篇博客为大家介绍双指针问题&#xff0c;它属于优选算法中的一种&#xff0c;也是一种很经典的算法&#xff1b;算法部分的学习对我们来说至关重要&#xff0c;它可以让我们积累解题思路&#xff0c;同时也可以大大提升我们的编程能力&#xff0c;本文主要是通过一些题…...

【Rabbitmq篇】RabbitMQ⾼级特性----消息确认

目录 前言&#xff1a; 一.消息确认机制 • ⾃动确认 • ⼿动确认 手动确认方法又分为三种&#xff1a; 二. 代码实现&#xff08;spring环境&#xff09; 配置相关信息&#xff1a; 1&#xff09;. AcknowledgeMode.NONE 2 &#xff09;AcknowledgeMode.AUTO 3&…...

开源TTS语音克隆神器GPT-SoVITS_V2版本地整合包部署与远程使用生成音频

文章目录 前言1.GPT-SoVITS V2下载2.本地运行GPT-SoVITS V23.简单使用演示4.安装内网穿透工具4.1 创建远程连接公网地址 5. 固定远程访问公网地址 前言 本文主要介绍如何在Windows系统电脑使用整合包一键部署开源TTS语音克隆神器GPT-SoVITS&#xff0c;并结合cpolar内网穿透工…...

【idea】更换快捷键

因为个人习惯问题需要把快捷键替换一下。我喜欢用CTRLD删除一下&#xff0c;用CTRLY复制一样。恰好这两个快捷键需要互换一下。 打开file——>setting——>Keymap——>Edit Actions 找到CTRLY并且把它删除 找到CTRLD 并且把它删除 鼠标右键添加CTRLY 同样操作在Delet…...

最小的子数组(leetcode 209)

给定一个正整数数组&#xff0c;找到大于等于s的连续的最小长度的区间。 解法一&#xff1a;暴力解法 两层for循环&#xff0c;一个区间终止位置&#xff0c;一个区间起始位置&#xff0c;找到大于等于s的最小区间长度&#xff08;超时了&#xff09; 解法二&#xff1a;双指…...

IDEA-Plugins无法下载插件(网络连接问题-HTTP Proxy Settings)

IDEA-Plugins无法下载插件&#xff08;网络连接问题&#xff09; 改成如下配置&#xff1a; 勾选 添这个url即可&#xff1a;https://plugins.jetbrains.com/ 重启插件中心&#xff0c;问题解决。...

AWTK-WIDGET-WEB-VIEW 发布

awtk-widget-web-view 是通过 webview 提供的接口&#xff0c;实现的 AWTK 自定义控件&#xff0c;使得 AWTK 可以方便的显示 web 页面。 项目网址&#xff1a; https://gitee.com/zlgopen/awtk-widget-web-view webview 提供了一个跨平台的 webview 接口&#xff0c;是一个非…...

Mysql每日一题(if函数)

两种写法if()和case if()函数 select *,if(T.xT.y>T.z and T.xT.z>T.y and T.yT.z>T.x,Yes,No) as triangle from Triangle as T; case方法 select *, case when T.xT.y>T.z and T.xT.z>T.y and T.yT.z>T.x then Yes else No end as triangle from Trian…...

Spring Cloud Alibaba [Gateway]网关。

1 简介 网关作为流量的入口&#xff0c;常用功能包括路由转发、权限校验、限流控制等。而springcloudgateway 作为SpringCloud 官方推出的第二代网关框架&#xff0c;取代了Zuul网关。 1.1 SpringCloudGateway特点: &#xff08;1&#xff09;基于Spring5&#xff0c;支持响应…...

【动手学深度学习Pytorch】2. Softmax回归代码

零实现 导入所需要的包&#xff1a; import torch from IPython import display from d2l import torch as d2l定义数据集参数、模型参数&#xff1a; batch_size 256 # 每次随机读取256张图片 train_iter, test_iter d2l.load_data_fashion_mnist(batch_size) # 将展平每个…...

技术周总结 11.11~11.17 周日(Js JVM XML)

文章目录 一、11.11 周一1.1&#xff09;问题01&#xff1a;js中的prompt弹窗区分出来用户点击的是 确认还是取消进一步示例 1.2&#xff09;问题02&#xff1a;在 prompt弹窗弹出时默认给弹窗中写入一些内容 二、11.12 周二2.1) 问题02: 详解JVM中的本地方法栈本地方法栈的主要…...

MATLAB 使用教程 —— 矩阵和数组

矩阵和数组MATLAB 中矩阵和数组长什么样&#xff1f;MATLAB 怎么用矩阵计算&#xff1f;创建和操作矩阵矩阵运算示例串联 访问矩阵的元素 矩阵和数组 MATLAB 是“matrix laboratory”的缩写形式。MATLAB 主要用于处理 整个的矩阵和数组&#xff0c;而其他编程语言大多逐个处理…...

React教程第二节之虚拟DOM与Diffing算法理解

1、什么是虚拟DOM 虚拟DOM 是javascript的一个对象&#xff0c;是内存中的一种数据结构&#xff0c;以树的形式存储UI的状态&#xff0c;树中的每个节点都代表着真实的DOM&#xff0c;用来描述我们希望在页面看到的 HTML结构&#xff1b; 现在的MVVM 框架&#xff0c;大多使用…...

C++——类和对象(part2)

前言 本篇博客继续为大家介绍类与对象的知识&#xff0c;承接part1的内容&#xff0c;本篇内容是类与对象的核心内容&#xff0c;稍微有些复杂&#xff0c;如果你对其感兴趣&#xff0c;请继续阅读&#xff0c;下面进入正文部分。 1. 类的默认成员函数 默认成员函数就是用户…...

【FFmpeg系列】:音频处理

前言 在多媒体处理领域&#xff0c;FFmpeg无疑是一个不可或缺的利器。它功能强大且高度灵活&#xff0c;能够轻松应对各种音频和视频处理任务&#xff0c;无论是简单的格式转换&#xff0c;还是复杂的音频编辑&#xff0c;都不在话下。然而&#xff0c;要想真正发挥FFmpeg的潜…...

Python绘制雪花

文章目录 系列目录写在前面技术需求完整代码代码分析1. 代码初始化部分分析2. 雪花绘制核心逻辑分析3. 窗口保持部分分析4. 美学与几何特点总结 写在后面 系列目录 序号直达链接爱心系列1Python制作一个无法拒绝的表白界面2Python满屏飘字表白代码3Python无限弹窗满屏表白代码4…...

vue3 如何调用第三方npm包内部的 pinia 状态管理库方法

抛砖引玉: 如果在开发vue3项目是, 引用了npm第三方包 ,而且这个包内使用了Pinia 状态管理库,那我们如何去调用 npm内部的 Pinia 状态管理库呢? 实际遇到的问题: 今天在制作npm包时遇到的问题,之前Vue2版本的时候状态管理库用的Vuex ,当时调用npm包内的状态管理库很简单,直接引…...

Python|GIF 解析与构建(5):手搓截屏和帧率控制

目录 Python&#xff5c;GIF 解析与构建&#xff08;5&#xff09;&#xff1a;手搓截屏和帧率控制 一、引言 二、技术实现&#xff1a;手搓截屏模块 2.1 核心原理 2.2 代码解析&#xff1a;ScreenshotData类 2.2.1 截图函数&#xff1a;capture_screen 三、技术实现&…...

变量 varablie 声明- Rust 变量 let mut 声明与 C/C++ 变量声明对比分析

一、变量声明设计&#xff1a;let 与 mut 的哲学解析 Rust 采用 let 声明变量并通过 mut 显式标记可变性&#xff0c;这种设计体现了语言的核心哲学。以下是深度解析&#xff1a; 1.1 设计理念剖析 安全优先原则&#xff1a;默认不可变强制开发者明确声明意图 let x 5; …...

FastAPI 教程:从入门到实践

FastAPI 是一个现代、快速&#xff08;高性能&#xff09;的 Web 框架&#xff0c;用于构建 API&#xff0c;支持 Python 3.6。它基于标准 Python 类型提示&#xff0c;易于学习且功能强大。以下是一个完整的 FastAPI 入门教程&#xff0c;涵盖从环境搭建到创建并运行一个简单的…...

1688商品列表API与其他数据源的对接思路

将1688商品列表API与其他数据源对接时&#xff0c;需结合业务场景设计数据流转链路&#xff0c;重点关注数据格式兼容性、接口调用频率控制及数据一致性维护。以下是具体对接思路及关键技术点&#xff1a; 一、核心对接场景与目标 商品数据同步 场景&#xff1a;将1688商品信息…...

Golang dig框架与GraphQL的完美结合

将 Go 的 Dig 依赖注入框架与 GraphQL 结合使用&#xff0c;可以显著提升应用程序的可维护性、可测试性以及灵活性。 Dig 是一个强大的依赖注入容器&#xff0c;能够帮助开发者更好地管理复杂的依赖关系&#xff0c;而 GraphQL 则是一种用于 API 的查询语言&#xff0c;能够提…...

linux 错误码总结

1,错误码的概念与作用 在Linux系统中,错误码是系统调用或库函数在执行失败时返回的特定数值,用于指示具体的错误类型。这些错误码通过全局变量errno来存储和传递,errno由操作系统维护,保存最近一次发生的错误信息。值得注意的是,errno的值在每次系统调用或函数调用失败时…...

【C语言练习】080. 使用C语言实现简单的数据库操作

080. 使用C语言实现简单的数据库操作 080. 使用C语言实现简单的数据库操作使用原生APIODBC接口第三方库ORM框架文件模拟1. 安装SQLite2. 示例代码:使用SQLite创建数据库、表和插入数据3. 编译和运行4. 示例运行输出:5. 注意事项6. 总结080. 使用C语言实现简单的数据库操作 在…...

使用Matplotlib创建炫酷的3D散点图:数据可视化的新维度

文章目录 基础实现代码代码解析进阶技巧1. 自定义点的大小和颜色2. 添加图例和样式美化3. 真实数据应用示例实用技巧与注意事项完整示例(带样式)应用场景在数据科学和可视化领域,三维图形能为我们提供更丰富的数据洞察。本文将手把手教你如何使用Python的Matplotlib库创建引…...

PAN/FPN

import torch import torch.nn as nn import torch.nn.functional as F import mathclass LowResQueryHighResKVAttention(nn.Module):"""方案 1: 低分辨率特征 (Query) 查询高分辨率特征 (Key, Value).输出分辨率与低分辨率输入相同。"""def __…...

Windows安装Miniconda

一、下载 https://www.anaconda.com/download/success 二、安装 三、配置镜像源 Anaconda/Miniconda pip 配置清华镜像源_anaconda配置清华源-CSDN博客 四、常用操作命令 Anaconda/Miniconda 基本操作命令_miniconda创建环境命令-CSDN博客...