Querylight TS Demo

Stats Aggregation

Get count, min, max, sum, and average from a numeric or date field in one call.

Back to docs search

Reference Entry

Stats Aggregation

Discovery · advanced · order 26

Get count, min, max, sum, and average from a numeric or date field in one call.

Stats Aggregation

stats() returns a compact metric summary for a numeric or date field.

Basic usage

const wordCountIndex = index.getFieldIndex("wordCount") as NumericFieldIndex;
const summary = wordCountIndex.stats();

Expected shape:

{
  count: 3,
  min: 250,
  max: 1400,
  sum: 2250,
  avg: 750
}

How it works

stats() combines:

  • valueCount()
  • min()
  • max()
  • sum()
  • avg()

into one result object.

If no values are available, it returns:

{
  count: 0,
  min: null,
  max: null,
  sum: 0,
  avg: null
}

When to use it

  • sidebar summaries
  • chart headers
  • quick diagnostics while exploring a filtered subset

Tradeoffs

  • If you only need one metric, a dedicated helper is simpler.