Skip to content

Commit

Permalink
Added MinAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattweber committed Mar 17, 2014
1 parent c728d10 commit 08361b1
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 @@ -3533,6 +3533,41 @@
return _common;
};

/**
@class
<p>A single-value metrics aggregation that keeps track and returns the
minimum value among 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.MinAggregation
@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 minimum value among numeric
values extracted from the aggregated documents.</p>

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

*/
ejs.MinAggregation = function (name) {

var
_common = ejs.MetricsAggregationMixin(name, 'min'),
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/MinAggregation.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
minimum value among 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.MinAggregation
@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 minimum value among numeric
values extracted from the aggregated documents.</p>
@param {String} name The name which be used to refer to this aggregation.
*/
ejs.MinAggregation = function (name) {

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

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

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

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

expected = {
myagg: {min: {}}
};

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

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

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

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

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

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

Please sign in to comment.