'Cannot get percentiles or value from Aggregation

enter image description here

The parentSalaries is a list of Buckets of size 1 and contains Aggregations of size 2, which are "precentials_salary" and "avg_salary". I am trying to get the percentiles values (5.0, 25.0 etc) and the value under the "average_salary" aggregation. However, there is no function like "getValue" or "getPercentiles" for the Aggregation.

I can see the data but can not extract them.

The code that I have is as below;

private void doSomething(Aggregations aggregations) {
 //aggregations is the Aggregations from the SearchResponse
 Terms parentSalaryRatio = aggregations.get("parent_salary_ratio");
 if (parentSalaryRatio != null) {
            List<? extends Terms.Bucket> parentSalaries = parentSalaryRatio.getBuckets();
            getTotalAvgSalaries(parentSalaries);
        }
}

 private void getTotalAvgSalaries(List<? extends Terms.Bucket> parentSalaries) {
      Aggregations aggregations = parentSalaries.get(0).getAggregations();
      Aggregation precentials = aggregations.get("precentials_salary");
      Aggregation precentials = aggregations.get("avg_salary");

}

Any help would be greatly appreciated.



Solution 1:[1]

found the issue;

I used ParsedSingleValueNumericMetricsAggregation to extract the "value" data. It has the value() function. The ParsedAvg can be used as well. It extends ParsedSingleValueNumericMetricsAggregation

And for the percentiles, I used ParsedTDigestPercentiles as P.J.Meisch suggested

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cugomastik