ValuesSearch.aggregate( name as stringOrUDF[] ) as ValuesSearch
Applies one or more aggregates to the values in the index. Exclusive with respect to the match(), groupInto(), orderBy(), slice(), map(), and reduce() clauses.
ValuesSearch.where
and
ValuesSearch.withOptions
clauses with this method.
You cannot use other query modifiers such as
ValuesSearch.slice
or ValuesSearch.orderBy
.
// Compute aggregates using built-in aggregate functions const jsearch = require('/MarkLogic/jsearch.sjs'); jsearch.values('price') .aggregate(['min','max','avg']) .result(); // Result: {"min":8, "max":30, "avg":16.125}
// Compute aggregates using a UDF const jsearch = require('/MarkLogic/jsearch.sjs'); jsearch.values('price') .aggregate(jsearch.udf('native/sampleplugin', 'count')) .result();