diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 4377d634982..08f42f2cf50 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -168,12 +168,22 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes }; this.testDatasource = function() { - timeSrv.setTime({ from: 'now-1m', to: 'now' }); - return this._get('/_stats').then(function() { - return { status: "success", message: "Data source is working", title: "Success" }; - }, function(err) { + timeSrv.setTime({ from: 'now-1m', to: 'now' }, true); + // validate that the index exist and has date field + return this.getFields({type: 'date'}).then(function(dateFields) { + var timeField = _.find(dateFields, {text: this.timeField}); + if (!timeField) { + return { status: "error", message: "No date field named " + this.timeField + ' found', title: "Error" }; + } + return { status: "success", message: "Index OK. Time field name OK.", title: "Success" }; + }.bind(this), function(err) { + console.log(err); if (err.data && err.data.error) { - return { status: "error", message: angular.toJson(err.data.error), title: "Error" }; + var message = angular.toJson(err.data.error); + if (err.data.error.reason) { + message = err.data.error.reason; + } + return { status: "error", message: message, title: "Error" }; } else { return { status: "error", message: err.status, title: "Error" }; } diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.js b/public/app/plugins/datasource/elasticsearch/query_builder.js index 808fea3cc70..fbbd4f7e929 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.js +++ b/public/app/plugins/datasource/elasticsearch/query_builder.js @@ -280,10 +280,12 @@ function (queryDef) { } }); } + var size = 500; - if(queryDef.size){ + if (queryDef.size) { size = queryDef.size; } + query.aggs = { "1": { "terms": {