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

Elasticsearch挂掉后,如何快速恢复数据

目录

一、Elasticsearch使用

二、实体类

2.1 mysql 实体类

 2.2 Elasticsearch实体类

三、XXL-job定时执行


一、Elasticsearch使用

  当我们做搜索功能时,如果为了提高查询效率,通常使用Elasticsearch搜索引擎加快搜索效率。以搜索商品为例,我们mysql肯定有一张商品表,对应的有一个实体类,而我们的es索引中,我们要多冗余两个字段,销量和好评。当用户搜索的时候,我们直接查Elasticsearch中的数据,但是当我们的Elasticsearch挂了之后,es数据会消失,我们可以用xxl-job做个定时任务,先查询mysql中的数据,再将数据库里的数据遍历出来再添加到Elasticsearch中。

二、实体类

2.1 mysql 实体类

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package com.beimao.common.model;import com.beimao.common.enums.ProductStatus;
import java.math.BigDecimal;public class Product extends BaseModel {private Integer id;private String name;private String subName;private Integer categoryId;private String img;private Integer status = 1;private String statusX;private BigDecimal price;private String brief;private Integer seq = 0;private String tags;public String getStatusX() {ProductStatus productStatus = ProductStatus.findByCode(this.status);return productStatus != null ? productStatus.getDesc() : "未定义";}public Product() {}public Integer getId() {return this.id;}public String getName() {return this.name;}public String getSubName() {return this.subName;}public Integer getCategoryId() {return this.categoryId;}public String getImg() {return this.img;}public Integer getStatus() {return this.status;}public BigDecimal getPrice() {return this.price;}public String getBrief() {return this.brief;}public Integer getSeq() {return this.seq;}public String getTags() {return this.tags;}public void setId(final Integer id) {this.id = id;}public void setName(final String name) {this.name = name;}public void setSubName(final String subName) {this.subName = subName;}public void setCategoryId(final Integer categoryId) {this.categoryId = categoryId;}public void setImg(final String img) {this.img = img;}public void setStatus(final Integer status) {this.status = status;}public void setStatusX(final String statusX) {this.statusX = statusX;}public void setPrice(final BigDecimal price) {this.price = price;}public void setBrief(final String brief) {this.brief = brief;}public void setSeq(final Integer seq) {this.seq = seq;}public void setTags(final String tags) {this.tags = tags;}public boolean equals(final Object o) {if (o == this) {return true;} else if (!(o instanceof Product)) {return false;} else {Product other = (Product)o;if (!other.canEqual(this)) {return false;} else {label143: {Object this$id = this.getId();Object other$id = other.getId();if (this$id == null) {if (other$id == null) {break label143;}} else if (this$id.equals(other$id)) {break label143;}return false;}Object this$categoryId = this.getCategoryId();Object other$categoryId = other.getCategoryId();if (this$categoryId == null) {if (other$categoryId != null) {return false;}} else if (!this$categoryId.equals(other$categoryId)) {return false;}Object this$status = this.getStatus();Object other$status = other.getStatus();if (this$status == null) {if (other$status != null) {return false;}} else if (!this$status.equals(other$status)) {return false;}label122: {Object this$seq = this.getSeq();Object other$seq = other.getSeq();if (this$seq == null) {if (other$seq == null) {break label122;}} else if (this$seq.equals(other$seq)) {break label122;}return false;}label115: {Object this$name = this.getName();Object other$name = other.getName();if (this$name == null) {if (other$name == null) {break label115;}} else if (this$name.equals(other$name)) {break label115;}return false;}Object this$subName = this.getSubName();Object other$subName = other.getSubName();if (this$subName == null) {if (other$subName != null) {return false;}} else if (!this$subName.equals(other$subName)) {return false;}Object this$img = this.getImg();Object other$img = other.getImg();if (this$img == null) {if (other$img != null) {return false;}} else if (!this$img.equals(other$img)) {return false;}label94: {Object this$statusX = this.getStatusX();Object other$statusX = other.getStatusX();if (this$statusX == null) {if (other$statusX == null) {break label94;}} else if (this$statusX.equals(other$statusX)) {break label94;}return false;}label87: {Object this$price = this.getPrice();Object other$price = other.getPrice();if (this$price == null) {if (other$price == null) {break label87;}} else if (this$price.equals(other$price)) {break label87;}return false;}Object this$brief = this.getBrief();Object other$brief = other.getBrief();if (this$brief == null) {if (other$brief != null) {return false;}} else if (!this$brief.equals(other$brief)) {return false;}Object this$tags = this.getTags();Object other$tags = other.getTags();if (this$tags == null) {if (other$tags != null) {return false;}} else if (!this$tags.equals(other$tags)) {return false;}return true;}}}protected boolean canEqual(final Object other) {return other instanceof Product;}public int hashCode() {int PRIME = true;int result = 1;Object $id = this.getId();result = result * 59 + ($id == null ? 43 : $id.hashCode());Object $categoryId = this.getCategoryId();result = result * 59 + ($categoryId == null ? 43 : $categoryId.hashCode());Object $status = this.getStatus();result = result * 59 + ($status == null ? 43 : $status.hashCode());Object $seq = this.getSeq();result = result * 59 + ($seq == null ? 43 : $seq.hashCode());Object $name = this.getName();result = result * 59 + ($name == null ? 43 : $name.hashCode());Object $subName = this.getSubName();result = result * 59 + ($subName == null ? 43 : $subName.hashCode());Object $img = this.getImg();result = result * 59 + ($img == null ? 43 : $img.hashCode());Object $statusX = this.getStatusX();result = result * 59 + ($statusX == null ? 43 : $statusX.hashCode());Object $price = this.getPrice();result = result * 59 + ($price == null ? 43 : $price.hashCode());Object $brief = this.getBrief();result = result * 59 + ($brief == null ? 43 : $brief.hashCode());Object $tags = this.getTags();result = result * 59 + ($tags == null ? 43 : $tags.hashCode());return result;}public String toString() {return "Product(id=" + this.getId() + ", name=" + this.getName() + ", subName=" + this.getSubName() + ", categoryId=" + this.getCategoryId() + ", img=" + this.getImg() + ", status=" + this.getStatus() + ", statusX=" + this.getStatusX() + ", price=" + this.getPrice() + ", brief=" + this.getBrief() + ", seq=" + this.getSeq() + ", tags=" + this.getTags() + ")";}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package com.beimao.common.model;import java.time.LocalDateTime;public abstract class BaseModel {private String lastUpdateBy;private LocalDateTime lastUpdateTime;public BaseModel() {}public String getLastUpdateBy() {return this.lastUpdateBy;}public void setLastUpdateBy(String lastUpdateBy) {this.lastUpdateBy = lastUpdateBy;}public LocalDateTime getLastUpdateTime() {return this.lastUpdateTime;}public void setLastUpdateTime(LocalDateTime lastUpdateTime) {this.lastUpdateTime = lastUpdateTime;}
}

 2.2 Elasticsearch实体类

package com.beimao.model;import cn.easyes.annotation.IndexField;
import cn.easyes.annotation.IndexId;
import cn.easyes.annotation.IndexName;
import cn.easyes.annotation.rely.Analyzer;
import cn.easyes.annotation.rely.FieldType;
import cn.easyes.annotation.rely.IdType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;/*** EsProduct 类用于表示一个商品实体,并定义了商品相关的属性。* 它使用了特定的注解来定义如何在搜索引擎中索引这些属性。*/
@IndexName(aliasName = "beimao_product") // 定义索引的别名
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class EsProduct {//商品id@IndexId(type = IdType.CUSTOMIZE) // 定义自定义的主键IDprivate Integer id;//商品名称@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_MAX_WORD, searchAnalyzer = Analyzer.IK_MAX_WORD)private String name;// 商品名称,使用IK分词器进行索引,便于全文检索//商品标签@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_MAX_WORD)private List<String> tags; //使用列表存储并使用IK分词器,便于检索具有多个标签的商品//商品副标题@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_MAX_WORD)private String subName;  // 假设subName也需要全文搜索//商品价格@IndexField(fieldType = FieldType.DOUBLE)private BigDecimal price;//商品状态@IndexField(fieldType = FieldType.INTEGER)private Integer status; // 使用KEYWORD类型更改为TEXT以示例中保持一致,实际根据需求可调整为FieldType.KEYWORD以进行精确匹配//商品品类private Integer categoryId; // 商品所属的类别ID//商品图片@IndexField(fieldType = FieldType.KEYWORD)private String img; // 商品图片链接,使用关键词类型索引,适用于精确匹配//商品简介@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_MAX_WORD)private String brief; // 商品简介,使用IK分词器进行索引,便于全文检索//商品排序@IndexField(fieldType = FieldType.INTEGER)private Integer sort;//商品库存@IndexField(fieldType = FieldType.INTEGER)private String stock;//商品好评数量@IndexField(fieldType = FieldType.INTEGER)private Integer highOpinion = 0; // 默认好评数量为0//商品销量@IndexField(fieldType = FieldType.INTEGER)private Integer salesVolume = 0; // 商品销量,整型存储}

三、XXL-job定时执行

相关文章:

Elasticsearch挂掉后,如何快速恢复数据

目录 一、Elasticsearch使用 二、实体类 2.1 mysql 实体类 2.2 Elasticsearch实体类 三、XXL-job定时执行 一、Elasticsearch使用 当我们做搜索功能时&#xff0c;如果为了提高查询效率&#xff0c;通常使用Elasticsearch搜索引擎加快搜索效率。以搜索商品为例&#xff0c;我…...

eNSP学习——连接RIP与OSPF网络、默认路由

目录 相关主要命令 实验一、连接RIP与OSPF网络 原理概述 实验目的 实验内容 实验拓扑 实验编址 实验步骤 1、基本配置 2、搭建RIP和OSPF网络 3、配置双向路由引入 4、手工配置引入时的开销值 实验二、使用OSPF、RIP发布默认路由 原理介绍 实验目的 实验内容 实…...

工具MyBatis Generator(MBG)

MyBatis Generator(MBG)&#xff0c;这是官方帮我们提供的一个自动生成代码的工具&#xff0c;前面的课程中&#xff0c;我们都是脑袋里想好&#xff0c;pojo有哪些属性&#xff0c;属性的类型是什么&#xff0c;对应的数据表中的字段名字是什么&#xff0c;匹配的类型是什么..…...

NeuralForecast 模型的参数 windows_batch的含义

NeuralForecast 模型的参数 windows_batch的含义 flyfish import pandas as pd import numpy as npAirPassengers np.array([112.0, 118.0, 132.0, 129.0, 121.0, 135.0, 148.0, 148.0, 136.0, 119.0],dtypenp.float32, )AirPassengersDF pd.DataFrame({"unique_id&qu…...

【记录】打印|用浏览器生成证件照打印PDF,打印在任意尺寸的纸上(简单无损!)

以前我打印证件照的时候&#xff0c;我总是在网上找在线证件照转换或者别的什么。但是我今天突然就琢磨了一下&#xff0c;用 PDF 打印应该也可以直接打印出来&#xff0c;然后就琢磨出来了&#xff0c;这么一条路大家可以参考一下。我觉得比在线转换成一张 a4 纸要方便的多&am…...

【python实现】实时监测GPU,空闲时自动执行脚本

文章目录 代码 代码 # author: muzhan # contact: levio.pkugmail.com import os import sys import time cmd nohup python -u train_post_2d_aut.py > output1.log & # gpu空闲时&#xff0c;需要执行的脚本命令 def gpu_info():gpu_status os.popen(nvidia-smi…...

chrome 浏览器历史版本下载

最近做一个项目,要使用到chrome浏览器比较久远的版本,在网上查找资源时,发现chrome比较老的版本的安装包特别难找,几经寻找,总算找到,具体方法如下 打开百度,搜索关键字【chrome版本号‘浏览迷’】&#xff0c;例如“chrome41浏览迷”&#xff0c;找到“全平台”开头的链接&am…...

【设计模式】工厂模式(创建型)⭐⭐⭐

文章目录 1.概念1.1 什么是工厂模式1.2 优点与缺点 2.实现方式2.1 简单工厂模式&#xff08;Simple Factory&#xff09;2.2 简单工厂模式缺点2.3 抽象工厂模式&#xff08;Abstract Factory Pattern&#xff09; 3 Java 哪些地方用到了工厂模式4 Spring 哪些地方用到了工厂模式…...

Postman 连接数据库 利用node+xmysql

1、准备nodejs环境 如果没有安装&#xff0c;在网上找教程&#xff0c;安装好后&#xff0c;在控制台输入命令查看版本&#xff0c;如下就成功了 2、安装xmysql 在控制台输入 npm install -g xmysql 3、连接目标数据库 帮助如下&#xff1a; 示例&#xff1a; 目标数据库…...

挑战你的数据结构技能:复习题来袭【6】

1. (单选题)设无向图的顶点个数为n,则该图最多有&#xff08;&#xff09;条边 A. n-1 B. n(n-1)/2 C. n(n1)/2 D. 0 答案&#xff1a;B 分析&#xff1a; 2. (单选题)含有n个顶点的连通无向图,其边的个数至少为()。 A. n-1 B. n C. n1 D. nlog2n 答案&#xff1a;A…...

如何反编译jar并修改后还原为jar

如何反编译jar并修改后还原为jar 目标:修改jar包中某个类的某个方法后还原为新的jar 1.新建android工程,把旧的jar添加为lib 2.用jadx-gui打开旧的jar并保存所有资源 3.找到保存的资源中想修改的.java类 4.复制类中的内容, 在android工程中新建一个同样路径的包,并在包下创建…...

统计信号处理基础 习题解答10-5

题目 通过令 并进行计算来重新推导MMSE估计量。提示&#xff1a;利用结果 解答 首先需要明确的是&#xff1a; 上式是关于观测值x 的函数 其次需要说明一下这个结果 和教材一样&#xff0c;我们用求期望&#xff0c;需要注意的是&#xff0c;在贝叶斯情况下&#xff0c;是个…...

Vue3实战笔记(60)—从零开始:一步步搭建Vue 3自定义插件

文章目录 前言一、自定义插件二、使用步骤总结 前言 在开发和学习中&#xff0c;经常使用一些好用的插件&#xff0c;那么如何创建一个自己的插件呢&#xff1f;在 Vue 3 中&#xff0c;你可以通过创建一个包含 install 方法的对象来定义自定义插件。install 方法接收两个参数…...

Java面向对象笔记

多态 一种类型的变量可以引用多种实际类型的对象 如 package ooplearn;public class Test {public static void main(String[] args) {Animal[] animals new Animal[2];animals[0] new Dog();animals[1] new Cat();for (Animal animal : animals){animal.eat();}} }class …...

如何通过PHP语言实现远程控制多路照明

如何通过PHP语言实现远程控制多路照明呢&#xff1f; 本文描述了使用PHP语言调用HTTP接口&#xff0c;实现控制多路照明&#xff0c;通过多路控制器&#xff0c;可独立远程控制多路照明。 可选用产品&#xff1a;可根据实际场景需求&#xff0c;选择对应的规格 序号设备名称厂…...

Capture One Pro 23:专业 Raw 图像处理的卓越之选

在当今的数字摄影时代&#xff0c;拥有一款强大的图像处理软件至关重要。而 Capture One Pro 23 for Mac/Win 无疑是其中的佼佼者&#xff0c;为摄影师和图像爱好者带来了前所未有的体验。 Capture One Pro 23 以其出色的 Raw 图像处理能力而闻名。它能够精准地解析和处理各种…...

【主题广泛|投稿优惠】2024年交通运输与信息科学国际会议(ICTIS 2024)

2024年交通运输与信息科学国际会议&#xff08;ICTIS 2024&#xff09; 2024 International Conference on Transportation and Information Science 【重要信息】 大会地点&#xff1a;青岛 大会官网&#xff1a;http://www.icictis.com 投稿邮箱&#xff1a;icictissub-conf.…...

表格误删数据保存关闭后如何恢复?5个恢复方法大公开!

“我在编辑表格的时候一不小心就删除了部分数据&#xff0c;现在真的不知道该怎么操作了。希望大家能帮帮我吧&#xff01;” 在日常工作中&#xff0c;我们经常会使用到各种表格软件来处理和分析数据。然而&#xff0c;有时由于操作失误或其他原因&#xff0c;我们可能会误删表…...

Go 语言中的切片:灵活的数据结构

切片&#xff08;slice&#xff09;是 Go 语言中一种非常重要且灵活的数据结构&#xff0c;它提供了对数组子序列的动态窗口。这使得切片在 Go 中的使用非常频繁&#xff0c;特别是在处理动态数据集时。本文将探讨切片的概念、操作和与函数的交互&#xff0c;以及如何有效地使用…...

在鲲鹏服务器搭建k8s高可用集群分享

高可用架构 本文采用kubeadm方式搭建k8s高可用集群&#xff0c;k8s高可用集群主要是对apiserver、etcd、controller-manager、scheduler做的高可用&#xff1b;高可用形式只要是为&#xff1a; 1. apiserver利用haproxykeepalived做的负载&#xff0c;多apiserver节点同时工作…...

多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度​

一、引言&#xff1a;多云环境的技术复杂性本质​​ 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时&#xff0c;​​基础设施的技术债呈现指数级积累​​。网络连接、身份认证、成本管理这三大核心挑战相互嵌套&#xff1a;跨云网络构建数据…...

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录

ASP.NET Core 是一个跨平台的开源框架&#xff0c;用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录&#xff0c;以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...

Android Wi-Fi 连接失败日志分析

1. Android wifi 关键日志总结 (1) Wi-Fi 断开 (CTRL-EVENT-DISCONNECTED reason3) 日志相关部分&#xff1a; 06-05 10:48:40.987 943 943 I wpa_supplicant: wlan0: CTRL-EVENT-DISCONNECTED bssid44:9b:c1:57:a8:90 reason3 locally_generated1解析&#xff1a; CTR…...

Unity3D中Gfx.WaitForPresent优化方案

前言 在Unity中&#xff0c;Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染&#xff08;即CPU被阻塞&#xff09;&#xff0c;这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案&#xff1a; 对惹&#xff0c;这里有一个游戏开发交流小组&…...

MFC内存泄露

1、泄露代码示例 void X::SetApplicationBtn() {CMFCRibbonApplicationButton* pBtn GetApplicationButton();// 获取 Ribbon Bar 指针// 创建自定义按钮CCustomRibbonAppButton* pCustomButton new CCustomRibbonAppButton();pCustomButton->SetImage(IDB_BITMAP_Jdp26)…...

在 Nginx Stream 层“改写”MQTT ngx_stream_mqtt_filter_module

1、为什么要修改 CONNECT 报文&#xff1f; 多租户隔离&#xff1a;自动为接入设备追加租户前缀&#xff0c;后端按 ClientID 拆分队列。零代码鉴权&#xff1a;将入站用户名替换为 OAuth Access-Token&#xff0c;后端 Broker 统一校验。灰度发布&#xff1a;根据 IP/地理位写…...

屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!

5月28日&#xff0c;中天合创屋面分布式光伏发电项目顺利并网发电&#xff0c;该项目位于内蒙古自治区鄂尔多斯市乌审旗&#xff0c;项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站&#xff0c;总装机容量为9.96MWp。 项目投运后&#xff0c;每年可节约标煤3670…...

python如何将word的doc另存为docx

将 DOCX 文件另存为 DOCX 格式&#xff08;Python 实现&#xff09; 在 Python 中&#xff0c;你可以使用 python-docx 库来操作 Word 文档。不过需要注意的是&#xff0c;.doc 是旧的 Word 格式&#xff0c;而 .docx 是新的基于 XML 的格式。python-docx 只能处理 .docx 格式…...

【决胜公务员考试】求职OMG——见面课测验1

2025最新版&#xff01;&#xff01;&#xff01;6.8截至答题&#xff0c;大家注意呀&#xff01; 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:&#xff08; B &#xff09; A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...

css3笔记 (1) 自用

outline: none 用于移除元素获得焦点时默认的轮廓线 broder:0 用于移除边框 font-size&#xff1a;0 用于设置字体不显示 list-style: none 消除<li> 标签默认样式 margin: xx auto 版心居中 width:100% 通栏 vertical-align 作用于行内元素 / 表格单元格&#xff…...