Java = 8 ElasticSearchServer = 7.16.3
我的代码从来不返回聚合的值,我尝试了大多数的组合。下面是代码,请看你是否能在这里提供帮助
@Repository
public interface ScPayHkIndexRepository extends ElasticsearchRepository<ScPayHkIndex, String> {
Stream<ScPayHkIndex> findByStatusNotAndExceptionTypeAndTimestampBetween(String status, String exceptionType, long from, long to);
Stream<ScPayHkIndex> findByPaymentTypeAndTimestampBetween(String paymentType, long from, long to);
@Query(("{\"bool\": {\"must\": [{\"match\": {\"status\": \"Completed\"}}]}},\"aggs\": {\"percentAggs\": {\"percentile_ranks\": {\"field\": \"Total_Time\"}}}"))
SearchHits<ScPayHkIndex> getPercentileRank();
default double getMyPercentileValue() {
SearchHits<ScPayHkIndex> response = getPercentileRank();
Aggregations aggregation = response.getAggregations();
PercentileRanks percentileRanks = aggregation.get("percentAggs");
// Get the desired percentile value using the percentile() method of the Percentiles object
double myPercentileValue = percentileRanks.percent(5000);
return myPercentileValue;
}
1条答案
按热度按时间k97glaaz1#
在Spring Data Elasticsearch中,您无法通过存储库查询获取聚合。您将需要创建一个具有所需聚合的
NativeQuery
,并需要使用ElasticsearchOperations
来处理该查询。你没有指定你使用的Spring Data Elasticsearch的版本,但是看看标签
resthighlevelclient
和Elasticsearch版本,你似乎在使用一个现在不推荐使用的旧版本。