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 Str
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今天的接口写完了吗?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值