diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js index ab1afa6a017..6e149e91384 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.js +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js @@ -13,6 +13,7 @@ function (angular, _, queryDef) { $scope.metricAggTypes = queryDef.metricAggTypes; $scope.extendedStats = queryDef.extendedStats; + $scope.mavgSourceOptions = []; $scope.init = function() { $scope.agg = metricAggs[$scope.index]; @@ -22,6 +23,7 @@ function (angular, _, queryDef) { $rootScope.onAppEvent('elastic-query-updated', function() { $scope.index = _.indexOf(metricAggs, $scope.agg); $scope.validateModel(); + $scope.updateMovingAverageOptions(); }, $scope); $scope.validateModel = function() { @@ -36,7 +38,8 @@ function (angular, _, queryDef) { switch($scope.agg.type) { case 'moving_avg': { - $scope.agg.aggregation = $scope.agg.aggregation || 'sum'; + $scope.agg.mavgSource = $scope.agg.mavgSource || ''; + $scope.settingsLinkText = 'Moving average options'; break; } case 'percentiles': { @@ -69,6 +72,11 @@ function (angular, _, queryDef) { $scope.toggleOptions = function() { $scope.showOptions = !$scope.showOptions; + $scope.updateMovingAverageOptions(); + }; + + $scope.onChangeInternal = function() { + $scope.onChange(); }; $scope.onTypeChange = function() { @@ -82,13 +90,6 @@ function (angular, _, queryDef) { return $scope.getFields({$fieldType: 'number'}); }; - $scope.getMetrics = function() { - var aggs = [{ text: 'Sum', type: 'sum'}, { text: 'Average', type: 'avg'}]; - - return $q.when(aggs) - .then(uiSegmentSrv.transformToSegments(false)); - }; - $scope.addMetricAgg = function() { var addIndex = metricAggs.length; @@ -100,6 +101,10 @@ function (angular, _, queryDef) { $scope.onChange(); }; + $scope.updateMovingAverageOptions = function() { + $scope.mvagSourceOptions = queryDef.getMovingAverageSourceOptions($scope.target); + }; + $scope.removeMetricAgg = function() { metricAggs.splice($scope.index, 1); $scope.onChange(); diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html index fd487d52d3b..2e34b28612d 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html @@ -9,9 +9,6 @@
  • -
  • - -
  • {{settingsLinkText}}
  • @@ -30,6 +27,17 @@
    +
    +
      +
    • + Based on +
    • +
    • + +
    • +
    +
    +
    • diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.js b/public/app/plugins/datasource/elasticsearch/query_builder.js index 5d1492640dd..5cd7d1dae50 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.js +++ b/public/app/plugins/datasource/elasticsearch/query_builder.js @@ -169,14 +169,9 @@ function () { var aggField = {}; var metricAgg = null; - if (metric.type === 'moving_avg') { - var subBucket = metric.id + "_mavg"; - - var af = {}; - af[metric.aggregation] = {field: metric.field}; - nestedAggs.aggs[subBucket] = af; - metricAgg = { buckets_path: subBucket }; + if (metric.type === 'moving_avg') { + metricAgg = {buckets_path: "1"}; } else { metricAgg = {field: metric.field}; } diff --git a/public/app/plugins/datasource/elasticsearch/query_def.js b/public/app/plugins/datasource/elasticsearch/query_def.js index 94401de778b..865c74753b3 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.js +++ b/public/app/plugins/datasource/elasticsearch/query_def.js @@ -13,7 +13,7 @@ function (_) { {text: "Min", value: 'min', requiresField: true}, {text: "Extended Stats", value: 'extended_stats', requiresField: true}, {text: "Percentiles", value: 'percentiles', requiresField: true}, - {text: "Moving Avg", value: 'moving_avg', requiresField: false, requiresBucketsPath: true}, + {text: "Moving Avg", value: 'moving_avg', requiresField: false }, {text: "Unique Count", value: "cardinality", requiresField: true}, {text: "Raw Document", value: "raw_document", requiresField: false} ],