ValuesSearch.aggregate

ValuesSearch.aggregate(
   name as stringOrUDF[]
) as ValuesSearch

Summary

Applies one or more aggregates to the values in the index. Exclusive with respect to the match(), groupInto(), orderBy(), slice(), map(), and reduce() clauses.

Parameters
name One or an array of built-in aggregate function names or aggregate user-defined function (UDF) reference. The allowed built-in aggregate names are "avg", "count", "max", "min", "stddev", "stddevp", "sum", "variance", or "variancep". To construct UDF reference, use the jsearch.udf helper function.

Usage Notes

You can only use the ValuesSearch.where and ValuesSearch.withOptions clauses with this method. You cannot use other query modifiers such as ValuesSearch.slice or ValuesSearch.orderBy.

See Also

Example


// 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}
   

Example


// Compute aggregates using a UDF
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.values('price')
  .aggregate(jsearch.udf('native/sampleplugin', 'count'))
  .result();
   
Powered by MarkLogic Server | Terms of Use | Privacy Policy