Skip to main content
$percentiles returns percentile cut points for a field. A percentile tells you the value below which a percentage of observations fall.
  • 50th percentile: median-like center point
  • 95th percentile: tail latency/price threshold
  • 99th percentile: extreme tail threshold

Compatibility

Field TypeSupported
TEXTNo
U64/I64/F64Yes
DATEYes
BOOLNo
KEYWORDNo
FACETNo
Field must be FAST.

Arguments

ArgumentTypeRequiredDescription
fieldstringYesField to aggregate.
percentsnumber[]NoPercent points to calculate (for example [50, 95, 99]).
keyedbooleanNoIf true (default), returns a map. If false, returns an array of { key, value }.
missingnumberNoFallback value for missing fields.
If percents is omitted, defaults to [1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0].
await index.aggregate({
  aggregations: {
    latency_pct: {
      $percentiles: { field: "latencyMs", percents: [50, 95, 99], keyed: true },
    },
  },
});

Output

keyed: true (default):
{
  "values": {
    "50.0": 40,
    "95.0": 76,
    "99.0": 79.2
  }
}
keyed: false:
{
  "values": [
    { "key": 50, "value": 40 },
    { "key": 95, "value": 76 },
    { "key": 99, "value": 79.2 }
  ]
}