Elasticsearch server state listener

Hey guys,

Is there a way by which i could get to know when elasticsearch server start/stops. Something like state listener.
I'm using java to connect to elasticsearch node. The java code is responsible for inserting documents into elasticsearch. If while inserting data, elasticsearch stops (or is killed manually), the documents should not be processed till the server is on. Although I get NoNodeAvailable exception in such case, but it would be better to get a listener interface for nodes.
Something like I have already implemented for cassandra using "Host.stateListener".

Any input appreciated :slight_smile:

Hey,

if you are using the TransportClient, you can use the sniffing option which polls the cluster state in the background to dynamically add or remove hosts to send queries to.

See https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html

--Alex

But that would require me to check the state every time right. I'm using TransportClient Sniffing option already, but only during initialization. Also, Currently its a single node cluster.
Currently the solution I'm looking for is,

class abc implements SomeListener
{
  @override
  public void onUp() {
    //Do something here
  }
  @override 
  public void onDown() {
    Do something
  }
}

So whenever elasticsearch is started, onUp() will be called, and when it shut downs, onDown() will be called.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.