Spring Boot Elasticsearch初级查询实现-ES索引名查询
注意:我的版本是elasticsearch7.6.2、spring-boot-starter-data-elasticsearch-2.5.6
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
ES分页查询接口实现,直接通过索引名称查询
@Override
public Page<AlarmHistoryVO> alarmHistoryPage(PageParams<FindHistoryDTO> pageParams, Boolean flag) {
//使用BoolQueryBuilder进行复合查询
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.termQuery("companyId", SecurityUtils.getCompanyId()));
if (StrUtil.isNotBlank(pageParams.getModel().getDeviceIp())){
boolQueryBuilder.must(QueryBuilders.termQuery("deviceIp",pageParams.getModel().getDeviceIp()));
}
if (StrUtil.isNotBlank(pageParams.getModel().getAlarmName())