elastic.js
Version:
Javascript API for ElasticSearch DSL
74 lines (58 loc) • 2.51 kB
JavaScript
/**
@class
<p>A single-value metrics aggregation that calculates an approximate count of
distinct values. Values can be extracted either from specific fields in the
document or generated by a script.</p>
@name ejs.CardinalityAggregation
@ejs aggregation
@borrows ejs.MetricsAggregationMixin.field as field
@borrows ejs.MetricsAggregationMixin.script as script
@borrows ejs.MetricsAggregationMixin.lang as lang
@borrows ejs.MetricsAggregationMixin.params as params
@borrows ejs.AggregationMixin._type as _type
@borrows ejs.AggregationMixin.toJSON as toJSON
@desc
<p>Aggregation that calculates an approximate count of distinct values.</p>
@param {String} name The name which be used to refer to this aggregation.
*/
ejs.CardinalityAggregation = function (name) {
var
_common = ejs.MetricsAggregationMixin(name, 'cardinality'),
agg = _common.toJSON();
// not supported in cardinality aggregation
delete _common.scriptValuesSorted;
return extend(_common, {
/**
Set to false to disable rehashing of values. You must have computed a hash
on the client-side and stored it into your documents if you disable this.
@member ejs.CardinalityAggregation
@param {Boolean} trueFalse set to false to disable rehashing
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
rehash: function (trueFalse) {
if (trueFalse == null) {
return agg[name].cardinality.rehash;
}
agg[name].cardinality.rehash = trueFalse;
return this;
},
/**
Allows to trade memory for accuracy, and defines a unique count below which
counts are expected to be close to accurate. Above this value, counts might
become a bit more fuzzy. The maximum supported value is 40000, thresholds
above this number will have the same effect as a threshold of 40000.
Default value depends on the number of parent aggregations that multiple
create buckets (such as terms or histograms).
@member ejs.CardinalityAggregation
@param {Long} num The threshold value
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
precisionThreshold: function (num) {
if (num == null) {
return agg[name].cardinality.precision_threshold;
}
agg[name].cardinality.precision_threshold = num;
return this;
}
});
};