elastic.js
Version:
Javascript API for ElasticSearch DSL
55 lines (42 loc) • 1.75 kB
JavaScript
/**
@class
<p>A single-value metrics aggregation that counts the number of values that
are extracted from the aggregated documents. These values can be extracted
either from specific fields in the documents, or be generated by a provided
script. Typically, this aggregator will be used in conjunction with other
single-value aggregations.</p>
@name ejs.ValueCountAggregation
@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 counts the number of values that are extracted from the
aggregated documents.</p>
@param {String} name The name which be used to refer to this aggregation.
*/
ejs.ValueCountAggregation = function (name) {
var
_common = ejs.MetricsAggregationMixin(name, 'value_count'),
agg = _common.toJSON();
// not supported in value count aggregation
delete _common.scriptValuesSorted;
return extend(_common, {
/**
Set to true to assume script values are unique.
@member ejs.ValueCountAggregation
@param {Boolean} trueFalse assume unique values or not
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
scriptValuesUnique: function (trueFalse) {
if (trueFalse == null) {
return agg[name].value_count.script_values_unique;
}
agg[name].value_count.script_values_unique = trueFalse;
return this;
}
});
};