Skip to content

Commit

Permalink
Added SumAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattweber committed Mar 17, 2014
1 parent ef3770a commit 01a7bb2
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 4 deletions.
35 changes: 35 additions & 0 deletions dist/elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4184,6 +4184,41 @@
return _common;
};

/**
@class
<p>A single-value metrics aggregation that sums up numeric values that are
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>

@name ejs.SumAggregation
@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 sums up numeric values that are extracted from the
aggregated documents.</p>

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

*/
ejs.SumAggregation = function (name) {

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

return _common;
};

/**
@class
<p>A multi-bucket value source based aggregation where buckets are dynamically
Expand Down
6 changes: 3 additions & 3 deletions dist/elastic.min.js

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions src/aggregations/SumAggregation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
@class
<p>A single-value metrics aggregation that sums up numeric values that are
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>
@name ejs.SumAggregation
@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 sums up numeric values that are extracted from the
aggregated documents.</p>
@param {String} name The name which be used to refer to this aggregation.
*/
ejs.SumAggregation = function (name) {

var
_common = ejs.MetricsAggregationMixin(name, 'sum'),
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(15);
test.expect(16);

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

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

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

expected = {
myagg: {sum: {}}
};

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

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

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

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

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

agg.params({p1: 'v1'});
expected.myagg.sum.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 01a7bb2

Please sign in to comment.