[[java-aggs-metrics-percentile-rank]] ==== Percentile Ranks Aggregation Here is how you can use {ref}/search-aggregations-metrics-percentile-rank-aggregation.html[Percentile Ranks Aggregation] with Java API. ===== Prepare aggregation request Here is an example on how to create the aggregation request: [source,java] -------------------------------------------------- PercentileRanksAggregationBuilder aggregation = AggregationBuilders .percentileRanks("agg") .field("height") .values(1.24, 1.91, 2.22); -------------------------------------------------- ===== Use aggregation response Import Aggregation definition classes: [source,java] -------------------------------------------------- import org.elasticsearch.search.aggregations.metrics.percentiles.Percentile; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; -------------------------------------------------- [source,java] -------------------------------------------------- // sr is here your SearchResponse object PercentileRanks agg = sr.getAggregations().get("agg"); // For each entry for (Percentile entry : agg) { double percent = entry.getPercent(); // Percent double value = entry.getValue(); // Value logger.info("percent [{}], value [{}]", percent, value); } -------------------------------------------------- This will basically produce: [source,text] -------------------------------------------------- percent [29.664353095090945], value [1.24] percent [73.9335313461868], value [1.91] percent [94.40095147327283], value [2.22] --------------------------------------------------