UNPKG

elastic-builder

Version:

A JavaScript implementation of the elasticsearch Query DSL

69 lines (56 loc) 2.47 kB
'use strict'; var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require('babel-runtime/helpers/inherits'); var _inherits3 = _interopRequireDefault(_inherits2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var MetricsAggregationBase = require('./metrics-aggregation-base'); /** * A multi-value metrics aggregation that computes stats over 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. * * The stats that are returned consist of: min, max, sum, count and avg. * * [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html) * * Aggregation that computes stats over numeric values extracted from the * aggregated documents. * * @example * const agg = esb.statsAggregation('grades_stats', 'grade'); * * * @example * // Use a file script * const agg = esb.statsAggregation('grades_stats').script( * esb.script('file', 'my_script').params({ field: 'price' }) * ); * * @example * // Value script to apply the conversion rate to every value * // before it is aggregated * const agg = esb.statsAggregation('grades_stats').script( * esb.script('inline', '_value * params.conversion_rate').params({ * conversion_rate: 1.2 * }) * ); * * @param {string} name The name which will be used to refer to this aggregation. * @param {string=} field The field to aggregate on * * @extends MetricsAggregationBase */ var StatsAggregation = function (_MetricsAggregationBa) { (0, _inherits3.default)(StatsAggregation, _MetricsAggregationBa); // eslint-disable-next-line require-jsdoc function StatsAggregation(name, field) { (0, _classCallCheck3.default)(this, StatsAggregation); return (0, _possibleConstructorReturn3.default)(this, (StatsAggregation.__proto__ || Object.getPrototypeOf(StatsAggregation)).call(this, name, 'stats', field)); } return StatsAggregation; }(MetricsAggregationBase); module.exports = StatsAggregation;