percentile.asciidoc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. [discrete]
  2. [[esql-agg-percentile]]
  3. === `PERCENTILE`
  4. *Syntax*
  5. [source,esql]
  6. ----
  7. PERCENTILE(expression, percentile)
  8. ----
  9. *Parameters*
  10. `expression`::
  11. Expression from which to return a percentile.
  12. `percentile`::
  13. A constant numeric expression.
  14. *Description*
  15. Returns the value at which a certain percentage of observed values occur. For
  16. example, the 95th percentile is the value which is greater than 95% of the
  17. observed values and the 50th percentile is the <<esql-agg-median>>.
  18. *Example*
  19. [source.merge.styled,esql]
  20. ----
  21. include::{esql-specs}/stats_percentile.csv-spec[tag=percentile]
  22. ----
  23. [%header.monospaced.styled,format=dsv,separator=|]
  24. |===
  25. include::{esql-specs}/stats_percentile.csv-spec[tag=percentile-result]
  26. |===
  27. The expression can use inline functions. For example, to calculate a percentile
  28. of the maximum values of a multivalued column, first use `MV_MAX` to get the
  29. maximum value per row, and use the result with the `PERCENTILE` function:
  30. [source.merge.styled,esql]
  31. ----
  32. include::{esql-specs}/stats_percentile.csv-spec[tag=docsStatsPercentileNestedExpression]
  33. ----
  34. [%header.monospaced.styled,format=dsv,separator=|]
  35. |===
  36. include::{esql-specs}/stats_percentile.csv-spec[tag=docsStatsPercentileNestedExpression-result]
  37. |===
  38. [discrete]
  39. [[esql-agg-percentile-approximate]]
  40. ==== `PERCENTILE` is (usually) approximate
  41. include::../../aggregations/metrics/percentile-aggregation.asciidoc[tag=approximate]
  42. [WARNING]
  43. ====
  44. `PERCENTILE` is also {wikipedia}/Nondeterministic_algorithm[non-deterministic].
  45. This means you can get slightly different results using the same data.
  46. ====