# Detect ES cluster node join/leave

**URL:** <https://discuss.elastic.co/t/detect-es-cluster-node-join-leave/3855>\
**Category:** Elasticsearch\
**Created:** [February 1, 2011, 8:16am UTC](https://discuss.elastic.co/t/detect-es-cluster-node-join-leave/3855 "2011-02-01T08:16:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwho](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@cwho](https://discuss.elastic.co/u/cwho)\
**Post date:** [February 1, 2011, 8:16am UTC](https://discuss.elastic.co/t/detect-es-cluster-node-join-leave/3855/1 "2011-02-01T08:16:09Z")

</div>

Hi,

We are using a elastic search cluster alongside our application  
cluster, and would like to be able to detect nodes joining/leaving  
(some sort of callback) so we can then do a index health check for  
availability. We are using 0.14.3 at the moment.

Right now we just do a index health check every 5-10 seconds, which is  
not optimal I think.

I looked through the source and was able to find ClusterStateListener,  
but this doesn't seem to be exposed via the Java API.

I like to know if this could be on the works (feature request) or  
already exists somewhere that we can make use of?

Thanks for a great search system!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 1, 2011, 7:42pm UTC](https://discuss.elastic.co/t/detect-es-cluster-node-join-leave/3855/2 "2011-02-01T19:42:42Z")

</div>

You can hack into it a bit, but its not exposed as an API. Doing an index status api is suboptimal, its much better to use the cluster health / cluster state API.

You can get the ClusterService if you cast the Node you get to InternalNode and get it from the Guice injector:

((InternalNode) node).injector().getInstance(ClusterService.class), and then register your listener there. _Note_, your callback should not do anything blocking or something that takes time on this calling thread!.

-shay.banon  
On Tuesday, February 1, 2011 at 10:16 AM, cwho80 wrote:

> Hi,
> 
> We are using a Elasticsearch cluster alongside our application  
> cluster, and would like to be able to detect nodes joining/leaving  
> (some sort of callback) so we can then do a index health check for  
> availability. We are using 0.14.3 at the moment.
> 
> Right now we just do a index health check every 5-10 seconds, which is  
> not optimal I think.
> 
> I looked through the source and was able to find ClusterStateListener,  
> but this doesn't seem to be exposed via the Java API.
> 
> I like to know if this could be on the works (feature request) or  
> already exists somewhere that we can make use of?
> 
> Thanks for a great search system!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:12am UTC](https://discuss.elastic.co/t/detect-es-cluster-node-join-leave/3855/3 "2017-07-06T04:12:57Z")

</div>


