Querylight TS Demo

Max Aggregation

Get the largest indexed numeric or date value, optionally restricted to the current result set.

Back to docs search

Reference Entry

Max Aggregation

Discovery · advanced · order 23

Get the largest indexed numeric or date value, optionally restricted to the current result set.

Max Aggregation

max() returns the largest indexed value in a numeric or date field.

Basic usage

const wordCountIndex = index.getFieldIndex("wordCount") as NumericFieldIndex;
const longest = wordCountIndex.max();

How it works

max() returns:

  • the largest stored value when one exists
  • null when the field or subset has no values
const longestInSubset = wordCountIndex.max(new Set(["a", "b"]));

When to use it

  • latest publication time
  • most expensive product
  • upper bound for range labels and charts

Tradeoffs

  • Like min(), date results are epoch milliseconds.