package com.jiuku.modules.es.service.impl;
import com.jiuku.modules.es.entity.AdminLogEntity;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import java.util.List;
* @Author: Hanweihu
* @Description:
* @Date: Created in 14:55 2021/3/12
public class Test {
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
* @Description: 筛选时间区间、must与should组合、分页查询、根据字段排序
* @author: Hanweihu
* @date: 2021/3/12 15:03
* @param pageNum 第几页
* @param limit 一页几条
public void testES(int pageNum, int limit) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
// must与should组合
.must(QueryBuilders.boolQuery().filter(QueryBuilders.wildcardQuery("会员ID字段", "*")))
.filter(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("资源类型字段", "api"))
.should(QueryBuilders.termQuery("资源类型字段", "page"))
// 筛选:时间区间
.filter(QueryBuilders.rangeQuery("时间字段").gte(开始时间long类型).lte(结束时间long类型));
SearchQuery nativeSearchQuery = new NativeSearchQueryBuilder()
.withQuery(boolQueryBuilder)
// 分页查询(注意:ES的页码是从0开始的)
.withPageable(PageRequest.of(pageNum - 1, limit))
// 根据字段排序
.withSort(SortBuilders.fieldSort("排序字段").order(SortOrder.valueOf("DESC")))
.build();
// 分页查询 AdminLogEntity是自定义的实体类,换成你们自己的
AggregatedPage<AdminLogEntity> goodsPage = elasticsearchTemplate.queryForPage(nativeSearchQuery, AdminLogEntity.class);
long total = goodsPage.getTotalElements(); // 总数据量
long totalPage = goodsPage.getTotalPages(); // 总页数
List<AdminLogEntity> goodsList = goodsPage.getContent(); // 当前页数据集合
【Elasticsearch】ES精确查询和范围查询,ES时间字段排序实例,ES倒排索引介绍。本文ES版本是7.X以上,之前的版本语法可能会有些差异,请注意这些比较重要的细节。问海量数据搜索时为什么ES会比较快?
#ElasticSearch 聚合查询之后会结果进行排序
// 声明where 条件
BoolQueryBuilder bqb = QueryBuilders.boolQuery();
// 根据时间条件查询
QueryBuilder qb1 = QueryBuilders.rangeQuery(&quot;create_date&quot;).from(start_time).to(end_time).inclu...
Markdown和扩展Markdown简洁的语法
**//多条件bool精准通配符查询
public JSON boolQuery(TransportClient client,JSONObject body){
SearchRequestBuilde...
/*** 加载查询条件* @param searchVO* @return*/public voidinitQuerySubjectbbsListBuilder(NativeSearchQueryBuilder queryBuilder, SubJectVO searchVO) {//复合查询BoolQueryBuilder boolQueryBuilder =QueryBuilders.bool...
public TransportClient transportClient(){
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch")
.build();
TransportClient client = new PreBuiltTransportClient(settings);
TransportAddres.
MySQL基础知识点前言一、MySQL是什么?二、MySQL的好处三、数据库的概念1. DB(database)2.DBMS(Database Management System)3.SQL(Structure Query Language)SQL的优点待更新学习
学习视频的链接:
[B站](https://www.bilibili.com/video/BV12b411K7Zu)
一、MySQL是什么?
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle
@Override
public PageResult fullTextSearch(FullTextParam param) {
Integer pageNum = param.getPageNum();.
@Autowired
private RestHighLevelClient client;
public List<Map<String,Object>> search(String index) {
List<Map<String,Object>> hitList = new ArrayList();
try {
//搜索请求
SearchRequest request = new
query.setPager(0,size);
query.includes( "id","tradeName","prd","coverImgId","coverImgSrc","ecoStatus","base64Image..
String startTime = "2021-06-01";
String endTime = "2021-06-02";
BoolQueryBuilder bqb = QueryBuilders.boolQuery();
bqb.must(QueryBuilders.matchPhraseQuery("userId",userStatisticsVO.getUserId()));
bqb.must(QueryBuilders.rang.
es存储日志 是按照UTC时间格式存放,以@timestamp 作为时间范围查询条件,即from(Date1) to(Date2)Date1、Date2入参必须是标准的utc格式;