Reference Entry
Max Aggregation
Discovery · advanced · order 23
Get the largest indexed numeric or date value, optionally restricted to the current result set.
Relevant APIs
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
nullwhen 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.