Metric Aggregations

$max

$max returns the maximum field value across matching documents.

If missing is set, missing fields are treated as that value.

Compatibility

Field TypeSupported
TEXTNo
U64/I64/F64Yes
DATEYes
BOOLYes
KEYWORDNo
FACETNo

Field must be FAST.

Arguments

ArgumentTypeRequiredDescription
fieldstringYesField to aggregate.
missingnumberNoFallback value for missing fields.
await index.aggregate({  aggregations: {    most_expensive: { $max: { field: "price", missing: 0 } },  },});
index.aggregate(    aggregations={"most_expensive": {"$max": {"field": "price", "missing": 0}}})
SEARCH.AGGREGATE products '{}' '{"most_expensive": {"$max": {"field": "price", "missing": 0}}}'

Output

{ "most_expensive": { "value": 80 } }

value can be null when no values are available.

Loading search…