From 9daa3997e98f3d31fc07f7d8b2ef6ff7a6ae6aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 4 Sep 2015 11:17:52 +0200 Subject: [PATCH] feat(elasticsearch): time field selector now works, #1034 --- .../elasticsearch/partials/query.editor.html | 5 ++- .../datasource/elasticsearch/queryBuilder.js | 20 ++++-------- .../datasource/elasticsearch/queryCtrl.js | 14 +++++++- .../graphite/partials/query.editor.html | 32 ++++++++----------- .../specs/elasticsearch-querybuilder-specs.js | 1 + 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html index 67dfd794186..0ecf582a50c 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html +++ b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html @@ -5,6 +5,9 @@ +
  • + {{target.datasource}} +
  • - +
  • diff --git a/public/app/plugins/datasource/elasticsearch/queryBuilder.js b/public/app/plugins/datasource/elasticsearch/queryBuilder.js index 5e674d43d22..2c19f5db65d 100644 --- a/public/app/plugins/datasource/elasticsearch/queryBuilder.js +++ b/public/app/plugins/datasource/elasticsearch/queryBuilder.js @@ -6,6 +6,12 @@ function (angular) { function ElasticQueryBuilder() { } + ElasticQueryBuilder.prototype.getRangeFilter = function(timeField) { + var filter = {}; + filter[timeField] = {"gte": "$timeFrom", "lte": "$timeTo"}; + return filter; + }; + ElasticQueryBuilder.prototype.build = function(target) { if (target.rawQuery) { return angular.fromJson(target.rawQuery); @@ -23,19 +29,7 @@ function (angular) { }, "filter": { "bool": { - "must": [ - { - "range": { - "@timestamp": { - "gte": "$timeFrom", - "lte": "$timeTo" - } - } - } - ], - "must_not": [ - - ] + "must": [{"range": this.getRangeFilter(target.timeField)}] } } } diff --git a/public/app/plugins/datasource/elasticsearch/queryCtrl.js b/public/app/plugins/datasource/elasticsearch/queryCtrl.js index 495f989b04b..03c6ad4d66d 100644 --- a/public/app/plugins/datasource/elasticsearch/queryCtrl.js +++ b/public/app/plugins/datasource/elasticsearch/queryCtrl.js @@ -143,7 +143,8 @@ function (angular, _, ElasticQueryBuilder) { }; $scope.getGroupByFields = function(segment) { - return $scope.datasource.metricFindQuery('fields()').then($scope.transformToSegments(false)) + return $scope.datasource.metricFindQuery('fields()') + .then($scope.transformToSegments(false)) .then(function(results) { if (segment.type !== 'plus-button') { results.splice(0, 0, angular.copy($scope.removeGroupBySegment)); @@ -153,6 +154,17 @@ function (angular, _, ElasticQueryBuilder) { .then(null, $scope.handleQueryError); }; + $scope.getTimeFields = function() { + return $scope.datasource.metricFindQuery('fields()') + .then($scope.transformToSegments(false)) + .then(null, $scope.handleQueryError); + }; + + $scope.timeFieldChanged = function() { + $scope.target.timeField = $scope.timeSegment.value; + $scope.queryUpdated(); + }; + $scope.groupByChanged = function(segment, index) { if (segment.value === $scope.removeGroupBySegment.value) { $scope.target.groupByFields.splice(index, 1); diff --git a/public/app/plugins/datasource/graphite/partials/query.editor.html b/public/app/plugins/datasource/graphite/partials/query.editor.html index 2de4b67dc6c..63d695833ec 100755 --- a/public/app/plugins/datasource/graphite/partials/query.editor.html +++ b/public/app/plugins/datasource/graphite/partials/query.editor.html @@ -49,24 +49,18 @@ - + - -
    - + +
    diff --git a/public/test/specs/elasticsearch-querybuilder-specs.js b/public/test/specs/elasticsearch-querybuilder-specs.js index b7aa8a332dc..edce5806f6c 100644 --- a/public/test/specs/elasticsearch-querybuilder-specs.js +++ b/public/test/specs/elasticsearch-querybuilder-specs.js @@ -9,6 +9,7 @@ define([ var builder = new ElasticQueryBuilder(); var query = builder.build({ + timeField: '@timestamp', select: [{agg: 'Count'}], groupByFields: [], });