elasticsearch根据某个字段来查询,以及通过时间筛选
String startTime = "2021-06-01";
String endTime = "2021-06-02";
BoolQueryBuilder bqb = QueryBuilders.boolQuery();
bqb.must(QueryBuilders.matchPhraseQuery("userId",userStatisticsVO.getUserId()));
bqb.must(QueryBuilders.rangeQuery("createTime").from(startTime).to(endTime));
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(bqb).withIndices("login_log").withTypes("login_log")
.withSearchType(SearchType.DEFAULT).build();
List<LoginLogDoc> list = elasticsearchTemplate.queryForList(searchQuery, LoginLogDoc.class);
int count = (int) elasticsearchTemplate.count(searchQuery);