ElasticsearchRestTemplate serch时,代码如图
day的格式是yyyy-MM-dd,当day的值是“2021-05-05”、“2021-06-06”这种月份和日相同的值时候查询到的数据会把当月的数据全部查询出来 就是day会匹配2021-05 、2021-06前缀的值都取出来,其它日期能正常过滤。
请问是什么原因呢?是is的语法问题吗?
您这个是什么版本?
我现在用的springdataelasticsearch,版本2.5.3,我的查询语句看起来是这样的:
public VehicleAggregationDto findVehicleWithAggGroup(@RequestBody FindVehicleParam param) {
VehicleAggregationDto vehicleAggregationDto = new VehicleAggregationDto();
NativeSearchQuery query = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.matchQuery("plate_number", param.getPlateNumber()))
//crossing_id 大于 2000
.withFilter(QueryBuilders.rangeQuery("crossing_id").gt(param.getCrossingId()))
.addAggregation(AggregationBuilders.dateHistogram("groupCreateTime").field("create_time")
.dateHistogramInterval(DateHistogramInterval.DAY)
.format("yyyy-MM-dd"))
.build();
SearchHits<Vehicle> result = template.search(query, Vehicle.class);
List<Vehicle> lists = result.getSearchHits().stream().map(SearchHit::getContent).collect(Collectors.toList());
vehicleAggregationDto.setVehicles(lists);
Map<String, Object> agg = new ConcurrentHashMap<>();
result.getAggregations().getAsMap().forEach((key, value) -> {
ParsedDateHistogram parse = (ParsedDateHistogram) value;
parse.getBuckets().forEach((i) -> {
ParsedDateHistogram.ParsedBucket bucket = (ParsedDateHistogram.ParsedBucket) i;
agg.put(bucket.getKeyAsString(), bucket.getDocCount());
});
});
vehicleAggregationDto.setAggregation(agg);
return vehicleAggregationDto;
}