//查询100条需要更新的project信息
public List<Project> getTopOutdatedProjectFromES(int size) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str1 = "2020-1-1 0:0:0";
Date time1 = null, time2 = null;
try {
time1 = sdf.parse(str1);
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MINUTE, -120);
time2=calendar.getTime();
} catch (Exception ex) {
log.info(ex.getMessage());
}
BoolQueryBuilder bqr1=QueryBuilders.boolQuery()
.must(QueryBuilders.existsQuery("projectMemberUpdatingTime"))
.must(QueryBuilders.rangeQuery("projectMemberUpdatingTime").from(time1).to(time2));
BoolQueryBuilder bqr2=QueryBuilders.boolQuery()
.mustNot(QueryBuilders.existsQuery("projectMemberUpdatingTime"));
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.should(bqr1);
boolQueryBuilder.should(bqr2);
QueryBuilder queryBuilder = QueryBuilders.boolQuery()
.mustNot(QueryBuilders.termQuery(DEL_FLAG, true))
.must(QueryBuilders.existsQuery("deptInfoListMap"))
.must(boolQueryBuilder)
;
PageRequest page = new PageRequest(0, size);
List<Project> projects = Lists.newArrayList(projectRepository.search(queryBuilder, page));
return projects;
}
ES: 分页查询
最新推荐文章于 2023-10-24 11:34:37 发布