java elasticSearchRepository 查询时间在600到2400的数据
您可以使用Elasticsearch的查询功能来筛选出时间在6:00到24:00之间的数据。具体的查询语句可以如下所示:
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
public interface MyElasticsearchRepository extends ElasticsearchRepository<MyDocument, String> {
@Query("{\"bool\":{\"must\":[{\"range\":{\"timestamp\":{\"gte\":\"06:00\",\"lt\":\"24:00\"}}}]}}")
List<MyDocument> findByTimestampBetween6And24();
}
在上述代码中,我们定义了一个Elasticsearch的repository接口 MyElasticsearchRepository,并且添加了一个自定义的查询方法 findByTimestampBetween6And24()。在该方法上通过 @Query 注解指定了具体的查询语句,使用了 Elasticsearch 的 range 查询来筛选出 timestamp 字段在6:00到24:00之间的数据。
请注意,由于 Elasticsearch 的时间字段通常以日期时间格式存储,因此您可能需要根据您的数据模型和字段类型进行适当的调整。此外,您还需要根据您的具体环境和需求对代码进行进一步的定制和调整
原文地址: https://www.cveoy.top/t/topic/ibS7 著作权归作者所有。请勿转载和采集!