forked from fullscale/elastic.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MetricsAggregationMixin and AvgAggregation.
The Metrics Aggregation Mixin can be used as the base for most metrics based aggregations. The AvgAggregation uses the metrics aggregation mixin for all methods.
- Loading branch information
Showing
5 changed files
with
341 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
@class | ||
<p>A single-value metrics aggregation that computes the average of 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.AvgAggregation | ||
@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 the average of numeric values that are extracted | ||
from the aggregated documents.</p> | ||
@param {String} name The name which be used to refer to this aggregation. | ||
*/ | ||
ejs.AvgAggregation = function (name) { | ||
|
||
var | ||
_common = ejs.MetricsAggregationMixin(name, 'avg'), | ||
agg = _common.toJSON(); | ||
|
||
return _common; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
@mixin | ||
<p>The MetricsAggregationMixin provides support for common options used across | ||
various metrics <code>Aggregation</code> implementations. This object should | ||
not be used directly.</p> | ||
@name ejs.MetricsAggregationMixin | ||
@ejs aggregation | ||
@borrows ejs.AggregationMixin.aggregation as aggregation | ||
@borrows ejs.AggregationMixin.agg as agg | ||
@borrows ejs.AggregationMixin._type as _type | ||
@borrows ejs.AggregationMixin.toJSON as toJSON | ||
*/ | ||
ejs.MetricsAggregationMixin = function (name, type) { | ||
|
||
var | ||
_common = ejs.AggregationMixin(name), | ||
agg = _common.toJSON(); | ||
|
||
agg[name][type] = {}; | ||
|
||
return extend(_common, { | ||
|
||
/** | ||
<p>Sets the field to operate on.</p> | ||
@member ejs.MetricsAggregationMixin | ||
@param {String} field a valid field name.. | ||
@returns {Object} returns <code>this</code> so that calls can be chained. | ||
*/ | ||
field: function (field) { | ||
if (field == null) { | ||
return agg[name][type].field; | ||
} | ||
|
||
agg[name][type].field = field; | ||
return this; | ||
}, | ||
|
||
/** | ||
Allows you generate or modify the terms/values using a script. | ||
@member ejs.MetricsAggregationMixin | ||
@param {String} scriptCode A valid script string to execute. | ||
@returns {Object} returns <code>this</code> so that calls can be chained. | ||
*/ | ||
script: function (scriptCode) { | ||
if (scriptCode == null) { | ||
return agg[name][type].script; | ||
} | ||
|
||
agg[name][type].script = scriptCode; | ||
return this; | ||
}, | ||
|
||
/** | ||
The script language being used. | ||
@member ejs.MetricsAggregationMixin | ||
@param {String} language The language of the script. | ||
@returns {Object} returns <code>this</code> so that calls can be chained. | ||
*/ | ||
lang: function (language) { | ||
if (language == null) { | ||
return agg[name][type].lang; | ||
} | ||
|
||
agg[name][type].lang = language; | ||
return this; | ||
}, | ||
|
||
/** | ||
Set to true to assume script values are sorted. | ||
@member ejs.MetricsAggregationMixin | ||
@param {Boolean} trueFalse assume sorted values or not | ||
@returns {Object} returns <code>this</code> so that calls can be chained. | ||
*/ | ||
scriptValuesSorted: function (trueFalse) { | ||
if (trueFalse == null) { | ||
return agg[name][type].script_values_sorted; | ||
} | ||
|
||
agg[name][type].script_values_sorted = trueFalse; | ||
return this; | ||
}, | ||
|
||
/** | ||
Sets parameters that will be applied to the script. Overwrites | ||
any existing params. | ||
@member ejs.MetricsAggregationMixin | ||
@param {Object} p An object where the keys are the parameter name and | ||
values are the parameter value. | ||
@returns {Object} returns <code>this</code> so that calls can be chained. | ||
*/ | ||
params: function (p) { | ||
if (p == null) { | ||
return agg[name][type].params; | ||
} | ||
|
||
agg[name][type].params = p; | ||
return this; | ||
} | ||
|
||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters