title: How to check if ElasticSearch client is connected?
body: <p>I'm working with <a href="https://github.com/elastic/elasticsearch-js" rel="noreferrer">elasticsearch-js</a> (NodeJS) and everything works just fine as long as long as ElasticSearch is running.  However, I'd like to know that my connection is alive before trying to invoke one of the client's methods.  I'm doing things in a bit of synchronous fashion, but only for the purpose of performance testing (e.g., check that I have an empty index to work in, ingest some data, query the data).  Looking at a snippet like this : </p>
  
  <pre><code>    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"});
      /// ...
  </code></pre>
  
  <p>Is there some mechanism to send in on the client config to fail fast, or some test I can perform on the client to make sure it's open before invoking <code>delete</code>?</p>
  
  <p><strong><em>Update: 2015-05-22</em></strong> <br/>
  I'm not sure if this is correct, but perhaps attempting to get client stats is reasonable?  </p>
  
  <pre><code>    var getStats = elasticClient.nodes.stats();
      getStats.then(function(o){
          console.log(o);
      })
      .catch(function(e){
          console.log(e);
          throw e;
      });
  </code></pre>
  
  <p>Via node-debug, I am seeing the promise rejected when ElasticSearch is down / inaccessible with: <code>"Error: No Living connections"</code>.  When it does connect, <code>o</code> in my then handler seems to have details about connection state.  Would this approach be correct or is there a preferred way to check connection viability?</p>