目录
一、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