Skip to main content
$histogram groups numeric values into fixed-width interval buckets. Use it for distribution charts when each bucket has the same width.

Compatibility

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

Arguments

ArgumentTypeRequiredDescription
fieldstringYesField to bucket on.
intervalnumberYesBucket width.
offsetnumberNoShift bucket boundaries.
minDocCountnumberNoExclude buckets with fewer docs.
hardBounds{ min: number, max: number }NoHard clamp for bucket range.
extendedBounds{ min: number, max: number }NoEmit buckets across this range, including empty ones.
keyedbooleanNoIf true, returns buckets as an object. Default: false.
For hardBounds and extendedBounds, both min and max are required.
await index.aggregate({
  aggregations: {
    price_distribution: {
      $histogram: { field: "price", interval: 25 },
    },
  },
});

Output

{
  "price_distribution": {
    "buckets": [
      { "key": 0, "docCount": 3 },
      { "key": 25, "docCount": 4 },
      { "key": 50, "docCount": 2 }
    ]
  }
}
Bucket entries can include keyAsString and nested sub-aggregation outputs.