Java = 8 ElasticSearchServer = 7.16.3
My code never returns the value for aggregations , I tried most of the combinations. Below is the code , please see if you can help here
@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;
}
You cannot get aggregations with repository queries in Spring Data Elasticsearch. You will need to create a
NativeQuerywith the required aggregations and need to use theElasticsearchOperationsto process that query.You do not specify what verison of Spring Data Elasticsearch you use, but looking at the tag
resthighlevelclientand the Elasticsearch version you seem to be using an old version which is deprecated now.