mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
elasticsearch: improve validation and error message when adding/testing elasticsearch ds, #7836
This commit is contained in:
parent
5702c57452
commit
3b235612fd
@ -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" };
|
||||
}
|
||||
|
@ -280,10 +280,12 @@ function (queryDef) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var size = 500;
|
||||
if(queryDef.size){
|
||||
if (queryDef.size) {
|
||||
size = queryDef.size;
|
||||
}
|
||||
|
||||
query.aggs = {
|
||||
"1": {
|
||||
"terms": {
|
||||
|
Loading…
Reference in New Issue
Block a user