From db9c288050714bb55ef85b3d131dab18a4f92d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 3 Dec 2015 18:30:36 +0100 Subject: [PATCH] fix(elasticsearch): refactoring of #3321 --- public/app/features/org/datasourceEditCtrl.js | 5 ++--- public/app/plugins/datasource/elasticsearch/datasource.js | 4 ++-- .../plugins/datasource/elasticsearch/partials/config.html | 4 ++-- .../app/plugins/datasource/elasticsearch/query_builder.js | 8 +++----- .../datasource/elasticsearch/specs/query_builder_specs.ts | 4 ++-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/public/app/features/org/datasourceEditCtrl.js b/public/app/features/org/datasourceEditCtrl.js index dd526f69308..b7f141f480e 100644 --- a/public/app/features/org/datasourceEditCtrl.js +++ b/public/app/features/org/datasourceEditCtrl.js @@ -13,7 +13,7 @@ function (angular, _, config) { $scope.httpConfigPartialSrc = 'app/features/org/partials/datasourceHttpConfig.html'; - var defaults = {name: '', type: 'graphite', url: '', access: 'proxy', jsonData: {'elasticsearchVersion': 2} }; + var defaults = {name: '', type: 'graphite', url: '', access: 'proxy', jsonData: {}}; $scope.indexPatternTypes = [ {name: 'No pattern', value: undefined}, @@ -24,8 +24,7 @@ function (angular, _, config) { {name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY'}, ]; - $scope.elasticsearchVersions = [ - {name: '0.x', value: 0}, + $scope.esVersions = [ {name: '1.x', value: 1}, {name: '2.x', value: 2}, ]; diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 642195130cd..1d846a7be17 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -23,11 +23,11 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes this.name = datasource.name; this.index = datasource.index; this.timeField = datasource.jsonData.timeField; - this.elasticsearchVersion = datasource.jsonData.elasticsearchVersion; + this.esVersion = datasource.jsonData.esVersion; this.indexPattern = new IndexPattern(datasource.index, datasource.jsonData.interval); this.queryBuilder = new ElasticQueryBuilder({ timeField: this.timeField, - elasticsearchVersion: this.elasticsearchVersion + esVersion: this.esVersion, }); } diff --git a/public/app/plugins/datasource/elasticsearch/partials/config.html b/public/app/plugins/datasource/elasticsearch/partials/config.html index ef596a4deef..81acd03809c 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/config.html +++ b/public/app/plugins/datasource/elasticsearch/partials/config.html @@ -34,10 +34,10 @@
diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.js b/public/app/plugins/datasource/elasticsearch/query_builder.js index 55b37da128c..de4e52a8e81 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.js +++ b/public/app/plugins/datasource/elasticsearch/query_builder.js @@ -5,15 +5,14 @@ function () { function ElasticQueryBuilder(options) { this.timeField = options.timeField; - this.elasticsearchVersion = options.elasticsearchVersion; + this.esVersion = options.esVersion; } ElasticQueryBuilder.prototype.getRangeFilter = function() { var filter = {}; filter[this.timeField] = {"gte": "$timeFrom", "lte": "$timeTo"}; - // elastic search versions 2.x require the time format to be specified - if (this.elasticsearchVersion >= 2) { + if (this.esVersion >= 2) { filter[this.timeField]["format"] = "epoch_millis"; } @@ -137,8 +136,7 @@ function () { "min_doc_count": 0, "extended_bounds": { "min": "$timeFrom", "max": "$timeTo" } }; - // elastic search versions 2.x require the time format to be specified - if (this.elasticsearchVersion >= 2) { + if (this.esVersion >= 2) { esAgg["date_histogram"]["format"] = "epoch_millis"; } break; diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts index 4c2ff1d34a3..3cfdf61620e 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts @@ -39,7 +39,7 @@ describe('ElasticQueryBuilder', function() { it('with es1.x and es2.x date histogram queries check time format', function() { var builder_2x = new ElasticQueryBuilder({ timeField: '@timestamp', - elasticsearchVersion: 2 + esVersion: 2 }); var query_params = { @@ -59,7 +59,7 @@ describe('ElasticQueryBuilder', function() { it('with es1.x and es2.x range filter check time format', function() { var builder_2x = new ElasticQueryBuilder({ timeField: '@timestamp', - elasticsearchVersion: 2 + esVersion: 2 }); // format should not be specified in 1.x queries