diff --git a/public/app/directives/metric.segment.js b/public/app/directives/metric.segment.js index 1697b752a74..953c92b6d3a 100644 --- a/public/app/directives/metric.segment.js +++ b/public/app/directives/metric.segment.js @@ -20,7 +20,6 @@ function (angular, app, _, $) { return { scope: { segment: "=", - noCustom: "=", getOptions: "&", onChange: "&", }, @@ -48,7 +47,7 @@ function (angular, app, _, $) { segment.fake = false; segment.expandable = selected.expandable; } - else if ($scope.noCustom === false) { + else if (segment.custom !== 'false') { segment.value = value; segment.html = $sce.trustAsHtml(value); segment.expandable = true; @@ -83,7 +82,7 @@ function (angular, app, _, $) { options = _.map($scope.altSegments, function(alt) { return alt.value; }); // add custom values - if ($scope.noCustom === false) { + if (segment.custom !== 'false') { if (!segment.fake && _.indexOf(options, segment.value) === -1) { options.unshift(segment.value); } @@ -161,7 +160,7 @@ function (angular, app, _, $) { .module('grafana.directives') .directive('metricSegmentModel', function(uiSegmentSrv, $q) { return { - template: '', + template: '', restrict: 'E', scope: { property: "=", @@ -175,9 +174,9 @@ function (angular, app, _, $) { $scope.valueToSegment = function(value) { var option = _.findWhere($scope.options, {value: value}); if (option) { - return uiSegmentSrv.newSegment({value: option.text, cssClass: attrs.cssClass}); + return uiSegmentSrv.newSegment({value: option.text, cssClass: attrs.cssClass, custom: attrs.custom}); } else { - return uiSegmentSrv.newSegment({value: value, cssClass: attrs.cssClass}); + return uiSegmentSrv.newSegment({value: value, cssClass: attrs.cssClass, custom: attrs.custom}); } }; diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 38b28b7fc02..ed5658d0e49 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -257,43 +257,19 @@ function (angular, _, config, kbn, moment, ElasticQueryBuilder) { var timeFrom = this.translateTime(timeSrv.time.from); var timeTo = this.translateTime(timeSrv.time.to); - var query = { - size: 10, - "query": { - "filtered": { - "filter": { - "bool": { - "must": [ - { - "range": { - "@timestamp": { - "gte": timeFrom, - "lte": timeTo - } - } - } - ], - } - } - } - } - }; - - return this._post('/_search?', query).then(function(res) { + return this._get('/_mapping').then(function(res) { var fields = {}; - for (var i = 0; i < res.hits.hits.length; i++) { - var hit = res.hits.hits[i]; - for (var field in hit) { - if (hit.hasOwnProperty(field) && field[0] !== '_') { - fields[field] = 1; - } - } - - if (hit._source) { - for (var fieldProp in hit._source) { - if (hit._source.hasOwnProperty(fieldProp)) { - fields[fieldProp] = 1; + for (var indexName in res) { + var index = res[indexName]; + var mappings = index.mappings; + if (!mappings) { continue; } + for (var typeName in mappings) { + var properties = mappings[typeName].properties; + for (var field in properties) { + var prop = properties[field]; + if (prop.type && field[0] !== '_') { + fields[field] = prop; } } } diff --git a/public/app/plugins/datasource/elasticsearch/metricAgg.js b/public/app/plugins/datasource/elasticsearch/metricAgg.js index fa5fa837c93..ef96c2600f6 100644 --- a/public/app/plugins/datasource/elasticsearch/metricAgg.js +++ b/public/app/plugins/datasource/elasticsearch/metricAgg.js @@ -27,6 +27,8 @@ function (angular, _, queryDef) { }); $scope.validateModel = function() { + $scope.settingsLinkText = ''; + if (!$scope.agg.field) { $scope.agg.field = 'select field'; } @@ -43,6 +45,7 @@ function (angular, _, queryDef) { $scope.onTypeChange = function() { $scope.agg.settings = {}; + $scope.validateModel(); $scope.onChange(); }; diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html b/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html index 6186ebba114..4ea6f53c402 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html @@ -5,7 +5,7 @@ Then by
  • - +
  • diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html index 6fcb49d49b0..e0f0512bfed 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html @@ -4,7 +4,7 @@ Metric
  • - +
  • diff --git a/public/app/services/uiSegmentSrv.js b/public/app/services/uiSegmentSrv.js index 539808cb01e..2973089b6ba 100644 --- a/public/app/services/uiSegmentSrv.js +++ b/public/app/services/uiSegmentSrv.js @@ -24,6 +24,7 @@ function (angular, _) { } this.cssClass = options.cssClass; + this.custom = options.custom; this.type = options.type; this.fake = options.fake; this.value = options.value;