Skip to content

Commit 4ce8178

Browse files
committed
Added ScriptedMetricAggregation #5
2 parents 6bf4045 + d5004e3 commit 4ce8178

File tree

5 files changed

+243
-8
lines changed

5 files changed

+243
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
dist/docs
2-
node_modules/
2+
node_modules/

dist/elastic.js

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! elastic.js - v1.3.0 - 2015-08-02
1+
/*! elastic.js - v1.3.0 - 2015-08-03
22
* https://github.com/fullscale/elastic.js
33
* Copyright (c) 2015 FullScale Labs, LLC; Licensed MIT */
44

@@ -5038,6 +5038,105 @@
50385038
});
50395039
};
50405040

5041+
/**
5042+
@class
5043+
<p>A single-value metrics aggregation that keeps track and returns the
5044+
minimum value among numeric values extracted from the aggregated documents.
5045+
These values can be extracted either from specific numeric fields in the
5046+
documents, or be generated by a provided script.</p>
5047+
5048+
@name ejs.MinAggregation
5049+
@ejs aggregation
5050+
@borrows ejs.MetricsAggregationMixin.field as field
5051+
@borrows ejs.MetricsAggregationMixin.script as script
5052+
@borrows ejs.MetricsAggregationMixin.lang as lang
5053+
@borrows ejs.MetricsAggregationMixin.scriptValuesSorted as scriptValuesSorted
5054+
@borrows ejs.MetricsAggregationMixin.params as params
5055+
@borrows ejs.AggregationMixin._type as _type
5056+
@borrows ejs.AggregationMixin.toJSON as toJSON
5057+
5058+
@desc
5059+
<p>Aggregation that keeps track and returns the minimum value among numeric
5060+
values extracted from the aggregated documents.</p>
5061+
5062+
@param {String} name The name which be used to refer to this aggregation.
5063+
5064+
*/
5065+
ejs.ScriptedMetricAggregation = function (name) {
5066+
5067+
var
5068+
_common = ejs.MetricsAggregationMixin(name, 'scripted_metric'),
5069+
agg = _common.toJSON();
5070+
5071+
delete _common.field;
5072+
5073+
return extend(_common, {
5074+
/**
5075+
<p>Sets the init_script_file.</p>
5076+
5077+
@member ejs.ScriptedMetricAggregation
5078+
@param {String} init_script_file A valid script file name.
5079+
@returns {Object} returns <code>this</code> so that calls can be chained.
5080+
*/
5081+
initScriptFile: function (init_script_file) {
5082+
if (init_script_file == null) {
5083+
return agg[name].scripted_metric.init_script_file;
5084+
}
5085+
5086+
agg[name].scripted_metric.init_script_file = init_script_file;
5087+
return this;
5088+
},
5089+
5090+
/**
5091+
<p>Sets the map_script_file.</p>
5092+
5093+
@member ejs.ScriptedMetricAggregation
5094+
@param {String} map_script_file A valid script file name.
5095+
@returns {Object} returns <code>this</code> so that calls can be chained.
5096+
*/
5097+
mapScriptFile : function (map_script_file) {
5098+
if (map_script_file == null) {
5099+
return agg[name].scripted_metric.map_script_file;
5100+
}
5101+
5102+
agg[name].scripted_metric.map_script_file = map_script_file;
5103+
return this;
5104+
},
5105+
5106+
/**
5107+
<p>Sets the combine_script_file.</p>
5108+
5109+
@member ejs.ScriptedMetricAggregation
5110+
@param {String} combine_script_file A valid script file name.
5111+
@returns {Object} returns <code>this</code> so that calls can be chained.
5112+
*/
5113+
combineScriptFile: function (combine_script_file) {
5114+
if (combine_script_file == null) {
5115+
return agg[name].scripted_metric.combine_script_file;
5116+
}
5117+
5118+
agg[name].scripted_metric.combine_script_file = combine_script_file;
5119+
return this;
5120+
},
5121+
5122+
/**
5123+
<p>Sets the reduce_script_file.</p>
5124+
5125+
@member ejs.ScriptedMetricAggregation
5126+
@param {String} reduce_script_file A valid script file name.
5127+
@returns {Object} returns <code>this</code> so that calls can be chained.
5128+
*/
5129+
reduceScriptFile: function (reduce_script_file) {
5130+
if (reduce_script_file == null) {
5131+
return agg[name].scripted_metric.reduce_script_file;
5132+
}
5133+
5134+
agg[name].scripted_metric.reduce_script_file = reduce_script_file;
5135+
return this;
5136+
}
5137+
});
5138+
};
5139+
50415140
/**
50425141
@class
50435142
<p>An aggregation that returns interesting or unusual occurrences of terms in

dist/elastic.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
@class
3+
<p>A single-value metrics aggregation that keeps track and returns the
4+
minimum value among numeric values extracted from the aggregated documents.
5+
These values can be extracted either from specific numeric fields in the
6+
documents, or be generated by a provided script.</p>
7+
8+
@name ejs.MinAggregation
9+
@ejs aggregation
10+
@borrows ejs.MetricsAggregationMixin.field as field
11+
@borrows ejs.MetricsAggregationMixin.script as script
12+
@borrows ejs.MetricsAggregationMixin.lang as lang
13+
@borrows ejs.MetricsAggregationMixin.scriptValuesSorted as scriptValuesSorted
14+
@borrows ejs.MetricsAggregationMixin.params as params
15+
@borrows ejs.AggregationMixin._type as _type
16+
@borrows ejs.AggregationMixin.toJSON as toJSON
17+
18+
@desc
19+
<p>Aggregation that keeps track and returns the minimum value among numeric
20+
values extracted from the aggregated documents.</p>
21+
22+
@param {String} name The name which be used to refer to this aggregation.
23+
24+
*/
25+
ejs.ScriptedMetricAggregation = function (name) {
26+
27+
var
28+
_common = ejs.MetricsAggregationMixin(name, 'scripted_metric'),
29+
agg = _common.toJSON();
30+
31+
delete _common.field;
32+
33+
return extend(_common, {
34+
/**
35+
<p>Sets the init_script_file.</p>
36+
37+
@member ejs.ScriptedMetricAggregation
38+
@param {String} init_script_file A valid script file name.
39+
@returns {Object} returns <code>this</code> so that calls can be chained.
40+
*/
41+
initScriptFile: function (init_script_file) {
42+
if (init_script_file == null) {
43+
return agg[name].scripted_metric.init_script_file;
44+
}
45+
46+
agg[name].scripted_metric.init_script_file = init_script_file;
47+
return this;
48+
},
49+
50+
/**
51+
<p>Sets the map_script_file.</p>
52+
53+
@member ejs.ScriptedMetricAggregation
54+
@param {String} map_script_file A valid script file name.
55+
@returns {Object} returns <code>this</code> so that calls can be chained.
56+
*/
57+
mapScriptFile : function (map_script_file) {
58+
if (map_script_file == null) {
59+
return agg[name].scripted_metric.map_script_file;
60+
}
61+
62+
agg[name].scripted_metric.map_script_file = map_script_file;
63+
return this;
64+
},
65+
66+
/**
67+
<p>Sets the combine_script_file.</p>
68+
69+
@member ejs.ScriptedMetricAggregation
70+
@param {String} combine_script_file A valid script file name.
71+
@returns {Object} returns <code>this</code> so that calls can be chained.
72+
*/
73+
combineScriptFile: function (combine_script_file) {
74+
if (combine_script_file == null) {
75+
return agg[name].scripted_metric.combine_script_file;
76+
}
77+
78+
agg[name].scripted_metric.combine_script_file = combine_script_file;
79+
return this;
80+
},
81+
82+
/**
83+
<p>Sets the reduce_script_file.</p>
84+
85+
@member ejs.ScriptedMetricAggregation
86+
@param {String} reduce_script_file A valid script file name.
87+
@returns {Object} returns <code>this</code> so that calls can be chained.
88+
*/
89+
reduceScriptFile: function (reduce_script_file) {
90+
if (reduce_script_file == null) {
91+
return agg[name].scripted_metric.reduce_script_file;
92+
}
93+
94+
agg[name].scripted_metric.reduce_script_file = reduce_script_file;
95+
return this;
96+
}
97+
});
98+
};

tests/aggregation_test.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exports.aggregations = {
2828
done();
2929
},
3030
exists: function (test) {
31-
test.expect(24);
31+
test.expect(25);
3232

3333
test.ok(ejs.GlobalAggregation, 'GlobalAggregation');
3434
test.ok(ejs.FilterAggregation, 'FilterAggregation');
@@ -54,6 +54,7 @@ exports.aggregations = {
5454
test.ok(ejs.IPv4RangeAggregation, 'IPv4RangeAggregation');
5555
test.ok(ejs.TopHitsAggregation, 'TopHitsAggregation');
5656
test.ok(ejs.GeoBoundsAggregation, 'GeoBoundsAggregation');
57+
test.ok(ejs.ScriptedMetricAggregation, 'ScriptedMetricAggregation');
5758

5859

5960
test.done();
@@ -1509,6 +1510,43 @@ exports.aggregations = {
15091510

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

1513+
test.done();
1514+
},
1515+
ScriptedMetricAggregation: function (test) {
1516+
test.expect(8);
1517+
1518+
var agg = ejs.ScriptedMetricAggregation('myagg'),
1519+
expected,
1520+
doTest = function () {
1521+
test.deepEqual(agg.toJSON(), expected);
1522+
};
1523+
1524+
expected = {
1525+
myagg: {scripted_metric: {}}
1526+
};
1527+
1528+
test.ok(agg, 'ScriptedMetricAggregation exists');
1529+
test.ok(agg.toJSON(), 'toJSON() works');
1530+
doTest();
1531+
1532+
agg.initScriptFile('s1');
1533+
expected.myagg.scripted_metric.init_script_file = 's1';
1534+
doTest();
1535+
1536+
agg.mapScriptFile('m1');
1537+
expected.myagg.scripted_metric.map_script_file = 'm1';
1538+
doTest();
1539+
1540+
agg.combineScriptFile('c1');
1541+
expected.myagg.scripted_metric.combine_script_file = 'c1';
1542+
doTest();
1543+
1544+
agg.reduceScriptFile('r1');
1545+
expected.myagg.scripted_metric.reduce_script_file = 'r1';
1546+
doTest();
1547+
1548+
test.strictEqual(agg._type(), 'aggregation');
1549+
15121550
test.done();
15131551
}
15141552
};

0 commit comments

Comments
 (0)