diff --git a/public/app/plugins/datasource/elasticsearch/directives.js b/public/app/plugins/datasource/elasticsearch/directives.js index b09c82b481e..a7ad8f6dfbf 100644 --- a/public/app/plugins/datasource/elasticsearch/directives.js +++ b/public/app/plugins/datasource/elasticsearch/directives.js @@ -30,6 +30,7 @@ function (angular) { index: "=", onChange: "&", getFields: "&", + esVersion: '=' } }; }); diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js index b4ef6a80b79..60a84e01e19 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.js +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js @@ -11,7 +11,7 @@ function (angular, _, queryDef) { module.controller('ElasticMetricAggCtrl', function($scope, uiSegmentSrv, $q, $rootScope) { var metricAggs = $scope.target.metrics; - $scope.metricAggTypes = queryDef.metricAggTypes; + $scope.metricAggTypes = queryDef.getMetricAggTypes($scope.esVersion); $scope.extendedStats = queryDef.extendedStats; $scope.pipelineAggOptions = []; diff --git a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html index d027e1a5c14..862a3d78254 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html +++ b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html @@ -65,7 +65,8 @@ + on-change="queryUpdated()" + es-version="esVersion"> diff --git a/public/app/plugins/datasource/elasticsearch/query_ctrl.js b/public/app/plugins/datasource/elasticsearch/query_ctrl.js index 203e064bfeb..b222733e29d 100644 --- a/public/app/plugins/datasource/elasticsearch/query_ctrl.js +++ b/public/app/plugins/datasource/elasticsearch/query_ctrl.js @@ -7,6 +7,7 @@ function (angular) { var module = angular.module('grafana.controllers'); module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv) { + $scope.esVersion = $scope.datasource.esVersion; $scope.init = function() { var target = $scope.target; diff --git a/public/app/plugins/datasource/elasticsearch/query_def.js b/public/app/plugins/datasource/elasticsearch/query_def.js index c798646db06..53c1fe378ef 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.js +++ b/public/app/plugins/datasource/elasticsearch/query_def.js @@ -14,8 +14,8 @@ function (_) { {text: "Extended Stats", value: 'extended_stats', requiresField: true, supportsMissing: true, supportsInlineScript: true}, {text: "Percentiles", value: 'percentiles', requiresField: true, supportsMissing: true, supportsInlineScript: true}, {text: "Unique Count", value: "cardinality", requiresField: true, supportsMissing: true}, - {text: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true }, - {text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true }, + {text: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true, minVersion: 2}, + {text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true, minVersion: 2 }, {text: "Raw Document", value: "raw_document", requiresField: false} ], @@ -76,6 +76,16 @@ function (_) { 'derivative': [] }, + getMetricAggTypes: function(esVersion) { + return _.filter(this.metricAggTypes, function(f) { + if (f.minVersion) { + return f.minVersion <= esVersion; + } else { + return true; + } + }); + }, + getPipelineOptions: function(metric) { if (!this.isPipelineAgg(metric.type)) { return []; diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts index e2fda224a6a..4552226d296 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts @@ -79,4 +79,24 @@ describe('ElasticQueryDef', function() { }); }); }); + + describe('pipeline aggs depending on esverison', function() { + describe('using esversion undefined', function() { + it('should not get pipeline aggs', function() { + expect(QueryDef.getMetricAggTypes(undefined).length).to.be(9); + }); + }); + + describe('using esversion 1', function() { + it('should not get pipeline aggs', function() { + expect(QueryDef.getMetricAggTypes(1).length).to.be(9); + }); + }); + + describe('using esversion 2', function() { + it('should get pipeline aggs', function() { + expect(QueryDef.getMetricAggTypes(2).length).to.be(11); + }); + }); + }); });