Commit 3b235612 by Torkel Ödegaard

elasticsearch: improve validation and error message when adding/testing elasticsearch ds, #7836

parent 5702c574
......@@ -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": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment