I work with elasticsearch-js (NodeJS) and everything works fine while ElasticSearch works. However, I would like to know that my connection is alive before trying to call one of the client methods. I do things a bit synchronously, but only for performance testing purposes (for example, check that I have an empty index for work, swallowing some data, requesting data). Looking at the fragment as follows:
var elasticClient = new elasticsearch.Client({ host: ((options.host || 'localhost') + ':' + (options.port || '9200')) }); // Note, I already have promise handling implemented, omitting it for brevity though var promise = elasticClient.indices.delete({index: "_all"}); /// ...
Is there some kind of mechanism to send in the client configuration so that it does not run quickly, or any test that I can run on the client to make sure it opens before calling delete ?
Update: 2015-05-22
I'm not sure if this is correct, but maybe trying to get customer statistics is reasonable?
var getStats = elasticClient.nodes.stats(); getStats.then(function(o){ console.log(o); }) .catch(function(e){ console.log(e); throw e; });
Through node-debug, I see that the promise is rejected when ElasticSearch is unavailable / unavailable: "Error: No Living connections" . When it connects, o in my handler seems to contain connection status information. Will this approach be correct or is there a preferred way to test the viability of the connection?
blong
source share