Commit 08a645e4 authored by shiyu's avatar shiyu

es随机查询,过滤数据

parent ba9f93dd
...@@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; ...@@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.xxdxxs.entity.Entity; import com.xxdxxs.entity.Entity;
import lombok.Data; import lombok.Data;
import java.util.Date;
@Data @Data
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class ItemOfEs implements Entity { public class ItemOfEs implements Entity {
...@@ -12,22 +14,117 @@ public class ItemOfEs implements Entity { ...@@ -12,22 +14,117 @@ public class ItemOfEs implements Entity {
private Long id; private Long id;
/** /**
* 商品id * 商品名称
*/ */
private String coin_id; private String name;
/** /**
* 商品名称 * 商品所属类目ID
*/ */
private String name; private Integer cid;
/**
* 是否上架
*/
private Boolean isOnSale;
/**
* 是否标准件
*/
private Boolean isStd;
/**
* 排序
*/
private Integer sort;
/**
* 商品分享朋友圈图片
*/
private String shareImage;
/** /**
* 置顶图片 * 置顶图片
*/ */
private String top_image_path; private String topImage;
/**
* 价格, 要除以100
*/
private Long price;
/**
* 创建时间
*/
private Date createTime;
/**
* 来源类型(1系统2用户上传)
*/
private Integer sourceType;
/**
* 更新时间
*/
private Date updateTime;
/**
* 逻辑删除
*/
private Boolean isDeleted;
/**
* 成交时间
*/
private String bidTime;
/**
* 备注说明
*/
private String remark;
/**
* 是否设置过
*/
private Integer isSetted;
/**
* 原始的资源url
*/
private String originalSourceUrl;
/**
* 来源7(1,2,3,,8,10,11):中国的
*/
private Integer source;
/**
* 商品种类1钱币
*/
private Integer kind;
/**
* 商品额外信息
*/
private String extra;
/**
* 商品图片,分号分隔
*/
private String images;
/**
* 商品视频, 分号分隔
*/
private String videos;
/**
* 商品详细介绍,是富文本格式
*/
private String detail;
/** /**
* 价格 * 原始额外信息
*/ */
private String price; private String originalExtra;
} }
...@@ -33,7 +33,11 @@ public class ItemEsDao { ...@@ -33,7 +33,11 @@ public class ItemEsDao {
private final static String INDEX = "quanku_temp"; private final static String INDEX = "quanku_temp";
//商品来源是中国,所对应的编码 //商品来源是中国,所对应的编码
private final static List<String> CHINESE_SOURCE_LIST = Arrays.asList("1", "2", "3", "7", "8", "10", "11", "1000"); private final static List<String> CHINESE_SOURCE_LIST = Arrays.asList("1", "2", "3", "7", "11", "1000");
//来源中国,排除2,7,尚未去除水印的
private final static List<String> SOURCE_LIST = Arrays.asList("1", "3", "8", "11", "1000");
@Resource(name="clientByPasswd") @Resource(name="clientByPasswd")
ElasticsearchClient elasticsearchClient; ElasticsearchClient elasticsearchClient;
...@@ -75,13 +79,13 @@ public class ItemEsDao { ...@@ -75,13 +79,13 @@ public class ItemEsDao {
int page = esSearchRequestDto.getPage(); int page = esSearchRequestDto.getPage();
int size = esSearchRequestDto.getSize(); int size = esSearchRequestDto.getSize();
int from = (page - 1) * size; int from = (page - 1) * size;
Query sourceTermQuery = TermQuery.of(t -> /* Query sourceTermQuery = TermQuery.of(t ->
t.field("source") t.field("source")
.value(2))._toQuery(); .value(2))._toQuery();
Query sourceTermQuery2 = TermQuery.of(t -> Query sourceTermQuery2 = TermQuery.of(t ->
t.field("source") t.field("source")
.value(7))._toQuery(); .value(7))._toQuery();*/
SearchRequest.Builder builder = new SearchRequest.Builder(); SearchRequest.Builder builder = new SearchRequest.Builder();
builder.index(INDEX); builder.index(INDEX);
...@@ -89,13 +93,13 @@ public class ItemEsDao { ...@@ -89,13 +93,13 @@ public class ItemEsDao {
builder.source(sourceBuild->sourceBuild.filter(f->f.includes(esSearchRequestDto.getIncludes()))); builder.source(sourceBuild->sourceBuild.filter(f->f.includes(esSearchRequestDto.getIncludes())));
} }
List<Query> sourceTypeQueryList = new ArrayList<>(); List<Query> sourceTypeQueryList = new ArrayList<>();
CHINESE_SOURCE_LIST.forEach(i -> { SOURCE_LIST.forEach(i -> {
Query query = TermQuery.of(t->t.field("sourceType").value(i))._toQuery(); Query query = TermQuery.of(t->t.field("source").value(i))._toQuery();
sourceTypeQueryList.add(query); sourceTypeQueryList.add(query);
}); });
Query shouldQuery = QueryBuilders.bool(q->q.should(sourceTypeQueryList)); Query shouldQuery = QueryBuilders.bool(q->q.should(sourceTypeQueryList));
BoolQuery.Builder build = QueryBuilders.bool().mustNot(sourceTermQuery).mustNot(sourceTermQuery2).must(shouldQuery); BoolQuery.Builder build = QueryBuilders.bool().must(shouldQuery);
if(StringUtils.hasLength(esSearchRequestDto.getContent())) { if(StringUtils.hasLength(esSearchRequestDto.getContent())) {
Query matchQuery = MatchQuery.of(m -> m Query matchQuery = MatchQuery.of(m -> m
.field("name") .field("name")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment