今天在使用es进行查询的时候遇到时间戳范围查询es数据导致,时间范围条件不成立,不知道是为什么。
这是es查询方法:
public SearchHits<SubReportPropertyMessage> searchByTimeRange(long startTime, long endTime) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
queryBuilder.must(QueryBuilders.rangeQuery("createTime")
.gte(startTime)
.lte(endTime));
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(queryBuilder).build();
// RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("createTime")
// .gte(startTime).lte(endTime);
//
// NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
// .withQuery(rangeQuery)
// .build();
// 执行查询并返回结果
SearchHits<SubReportPropertyMessage> searchHits = elasticsearchRestTemplate.search(searchQuery, SubReportPropertyMessage.class);
return searchHits;
}
{
"_index": "abs_report_property",
"_type": "_doc",
"_id": "1373",
"_version": 1,
"_score": 1,
"_source": {
"_class": "com.hyzk.mqtt.client.domain.message.SubReportPropertyMessage",
"clientId": "2311220001",
"topic": "/sys/thing/node/property/post",
"deviceAddr": "KT0001G11",
"params": [
{
"deviceAddr": "KT0001G11",
"properties": "[{"name":"AirSet","value":2,"timestamp":1710724043},{"name":"Channel","value":0,"timestamp":1710724044},{"name":"ModeSet","value":0,"timestamp":1710724043},{"name":"Pa","value":0,"timestamp":1710724042},{"name":"RoomTemp","value":17.3,"timestamp":1710724042},{"name":"TempSet","value":20,"timestamp":1710724043},{"name":"Ua","value":230.6,"timestamp":1710724042},{"name":"Ic","value":0,"timestamp":1710724042},{"name":"NETID","value":0,"timestamp":1710724044},{"name":"RoomHumi","value":54,"timestamp":1710724042},{"name":"TotalEnergy","value":0,"timestamp":1710724042},{"name":"AirBrandID","value":40,"timestamp":1710724043},{"name":"Ia","value":6,"timestamp":1710724042},{"name":"Ib","value":0,"timestamp":1710724042},{"name":"Pb","value":0,"timestamp":1710724042},{"name":"Pc","value":0,"timestamp":1710724042},{"name":"SoftVer","value":133,"timestamp":1710724043},{"name":"StartStopSet","value":0,"timestamp":1710724043},{"name":"TotalTime","value":31458,"timestamp":1710724042},{"name":"Uc","value":0,"timestamp":1710724042},{"name":"DeviceType","value":2,"timestamp":1710724043},{"name":"OpeningCurrent","value":3,"timestamp":1710724044},{"name":"StartStopStatus","value":1,"timestamp":1710724042},{"name":"Ub","value":0,"timestamp":1710724042}]"
}
],
"topicMessageEnum": "absReportProperty",
"createTime": 1710724493704,
"id": "1373",
"version": "V1.0",
"ack": 1
}
}