Skip to content

Commit

Permalink
Improved index resolving efficiency
Browse files Browse the repository at this point in the history
Instead of getting all indices in the cluster and the filter what we need, we try to resolve the indices we care about.
  • Loading branch information
bleskes committed Jan 4, 2014
1 parent fb7e4b6 commit 4ad4627
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/app/services/kbnIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function (angular, _, config, moment) {
possible.push(d.format(pattern));
});

return all_indices().then(function(p) {
return resolve_indices(possible).then(function(p) {
// an extra intersection
var indices = _.intersection(possible,p);
indices.reverse();
return indices;
Expand All @@ -27,18 +28,12 @@ function (angular, _, config, moment) {

// returns a promise containing an array of all indices in an elasticsearch
// cluster
function all_indices() {
var something = $http({
url: config.elasticsearch + "/_aliases",
function resolve_indices(indices) {
var something;
indices = _.map(indices, encodeURIComponent);
something = $http({
url: config.elasticsearch + "/" + indices.join(",") + "/_aliases?ignore_missing=true",
method: "GET"
}).error(function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"Could not reach "+config.elasticsearch+"/_aliases. If you"+
" are using a proxy, ensure it is configured correctly",'error');
}
});

return something.then(function(p) {
Expand All @@ -51,7 +46,19 @@ function (angular, _, config, moment) {
});
});
return indices;
});
}, function (p) {
if (p.status === 404) {
return [];
}
else if(p.status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"Could not reach "+config.elasticsearch+"/_aliases. If you"+
" are using a proxy, ensure it is configured correctly",'error');
}
return [];
});
}

// this is stupid, but there is otherwise no good way to ensure that when
Expand Down

0 comments on commit 4ad4627

Please sign in to comment.