Skip to content

Commit

Permalink
Added ExtendedStatsAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattweber committed Mar 17, 2014
1 parent 9419396 commit 097055f
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 4 deletions.
39 changes: 39 additions & 0 deletions dist/elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,45 @@

};

/**
@class
<p>A multi-value metrics aggregation that computes stats over numeric values
extracted from the aggregated documents. These values can be extracted either
from specific numeric fields in the documents, or be generated by a provided
script.</p>

<p>The extended_stats aggregations is an extended version of the
<code>StatsAggregation</code>, where additional metrics are added such as
sum_of_squares, variance and std_deviation.</p>

@name ejs.ExtendedStatsAggregation
@ejs aggregation
@borrows ejs.MetricsAggregationMixin.field as field
@borrows ejs.MetricsAggregationMixin.script as script
@borrows ejs.MetricsAggregationMixin.lang as lang
@borrows ejs.MetricsAggregationMixin.scriptValuesSorted as scriptValuesSorted
@borrows ejs.MetricsAggregationMixin.params as params
@borrows ejs.MetricsAggregationMixin.aggregation as aggregation
@borrows ejs.MetricsAggregationMixin.agg as agg
@borrows ejs.MetricsAggregationMixin._type as _type
@borrows ejs.MetricsAggregationMixin.toJSON as toJSON

@desc
<p>Aggregation that computes extra stats over numeric values extracted from
the aggregated documents.</p>

@param {String} name The name which be used to refer to this aggregation.

*/
ejs.ExtendedStatsAggregation = function (name) {

var
_common = ejs.MetricsAggregationMixin(name, 'extended_stats'),
agg = _common.toJSON();

return _common;
};

/**
@class
<p>Defines a single bucket of all the documents in the current document set
Expand Down
6 changes: 3 additions & 3 deletions dist/elastic.min.js

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions src/aggregations/ExtendedStatsAggregation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
@class
<p>A multi-value metrics aggregation that computes stats over numeric values
extracted from the aggregated documents. These values can be extracted either
from specific numeric fields in the documents, or be generated by a provided
script.</p>
<p>The extended_stats aggregations is an extended version of the
<code>StatsAggregation</code>, where additional metrics are added such as
sum_of_squares, variance and std_deviation.</p>
@name ejs.ExtendedStatsAggregation
@ejs aggregation
@borrows ejs.MetricsAggregationMixin.field as field
@borrows ejs.MetricsAggregationMixin.script as script
@borrows ejs.MetricsAggregationMixin.lang as lang
@borrows ejs.MetricsAggregationMixin.scriptValuesSorted as scriptValuesSorted
@borrows ejs.MetricsAggregationMixin.params as params
@borrows ejs.MetricsAggregationMixin.aggregation as aggregation
@borrows ejs.MetricsAggregationMixin.agg as agg
@borrows ejs.MetricsAggregationMixin._type as _type
@borrows ejs.MetricsAggregationMixin.toJSON as toJSON
@desc
<p>Aggregation that computes extra stats over numeric values extracted from
the aggregated documents.</p>
@param {String} name The name which be used to refer to this aggregation.
*/
ejs.ExtendedStatsAggregation = function (name) {

var
_common = ejs.MetricsAggregationMixin(name, 'extended_stats'),
agg = _common.toJSON();

return _common;
};
53 changes: 52 additions & 1 deletion tests/aggregation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.aggregations = {
done();
},
exists: function (test) {
test.expect(17);
test.expect(18);

test.ok(ejs.GlobalAggregation, 'GlobalAggregation');
test.ok(ejs.FilterAggregation, 'FilterAggregation');
Expand All @@ -47,6 +47,57 @@ exports.aggregations = {
test.ok(ejs.StatsAggregation, 'StatsAggregation');
test.ok(ejs.SumAggregation, 'SumAggregation');
test.ok(ejs.ValueCountAggregation, 'ValueCountAggregation');
test.ok(ejs.ExtendedStatsAggregation, 'ExtendedStatsAggregation');

test.done();
},
ExtendedStatsAggregation: function (test) {
test.expect(11);

var agg = ejs.ExtendedStatsAggregation('myagg'),
ta1 = ejs.TermsAggregation('ta1').field('f1'),
expected,
doTest = function () {
test.deepEqual(agg.toJSON(), expected);
};

expected = {
myagg: {extended_stats: {}}
};

test.ok(agg, 'ExtendedStatsAggregation exists');
test.ok(agg.toJSON(), 'toJSON() works');
doTest();

agg.field('f1');
expected.myagg.extended_stats.field = 'f1';
doTest();

agg.script('s1');
expected.myagg.extended_stats.script = 's1';
doTest();

agg.lang('mvel');
expected.myagg.extended_stats.lang = 'mvel';
doTest();

agg.scriptValuesSorted(false);
expected.myagg.extended_stats.script_values_sorted = false;
doTest();

agg.params({p1: 'v1'});
expected.myagg.extended_stats.params = {p1: 'v1'};
doTest();

agg.agg(ta1);
expected.myagg.aggs = ta1.toJSON();
doTest();

test.strictEqual(agg._type(), 'aggregation');

test.throws(function () {
agg.agggregation('invalid');
}, TypeError);

test.done();
},
Expand Down

0 comments on commit 097055f

Please sign in to comment.