Skip to content

Commit

Permalink
Added MaxAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattweber committed Mar 17, 2014
1 parent 35a2d3c commit c728d10
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 @@ -3498,6 +3498,41 @@
});
};

/**
@class
<p>A single-value metrics aggregation that keeps track and returns the
maximum value among the 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>

@name ejs.MaxAggregation
@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 keeps track and returns the maximum value among the
numeric values extracted from the aggregated documents.</p>

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

*/
ejs.MaxAggregation = function (name) {

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

return _common;
};

/**
@class
<p>A field data based single bucket aggregation, that creates a bucket of all
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/MaxAggregation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
@class
<p>A single-value metrics aggregation that keeps track and returns the
maximum value among the 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>
@name ejs.MaxAggregation
@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 keeps track and returns the maximum value among the
numeric values extracted from the aggregated documents.</p>
@param {String} name The name which be used to refer to this aggregation.
*/
ejs.MaxAggregation = function (name) {

var
_common = ejs.MetricsAggregationMixin(name, 'max'),
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(11);
test.expect(12);

test.ok(ejs.GlobalAggregation, 'GlobalAggregation');
test.ok(ejs.FilterAggregation, 'FilterAggregation');
Expand All @@ -41,6 +41,57 @@ exports.aggregations = {
test.ok(ejs.SignificantTermsAggregation, 'SignificantTermsAggregation');
test.ok(ejs.AvgAggregation, 'AvgAggregation');
test.ok(ejs.CardinalityAggregation, 'CardinalityAggregation');
test.ok(ejs.MaxAggregation, 'MaxAggregation');

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

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

expected = {
myagg: {max: {}}
};

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

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

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

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

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

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

Please sign in to comment.