# Determine Node is safe to Terminate

**URL:** <https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230>\
**Category:** Elasticsearch\
**Created:** [April 10, 2019, 1:52pm UTC](https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230 "2019-04-10T13:52:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tebriel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tebriel/32/44889_2.png) [@tebriel](https://discuss.elastic.co/u/tebriel)\
**Post date:** [April 10, 2019, 1:52pm UTC](https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230/1 "2019-04-10T13:52:11Z")

</div>

I'm trying to determine if a node is safe to be terminated after using a routing exclusion. Is the only way to do this to traverse the cluster state and be sure it doesn't have any shards left? I see that the Monitoring UI knows how many shards are on a particular node, but I'm unable to find that information in the API. Thanks!

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 3:01pm UTC](https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230/2 "2019-04-10T15:01:20Z")

</div>

[`GET _cluster/health?wait_for_no_relocating_shards&timeout=24h`](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html) waits for all relocations to finish, up to 24 hours. Or you can poll `GET _cat/allocation/NODE_NAME` - the first number returned is the number of shards on that node.

---

<div class="post-metadata">

**Author:** ![tebriel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tebriel/32/44889_2.png) [@tebriel](https://discuss.elastic.co/u/tebriel)\
**Post date:** [April 10, 2019, 11:25pm UTC](https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230/3 "2019-04-10T23:25:34Z")

</div>

Thanks @DavidTurner this is very helpful. Can I rely on the allocations or is there a chance I could catch it between one finishing and the next starting? I may use the cat api for allocations as that will let me poll and do other work between. Using both would give me more peace of mind though. I’m torn.  
Thanks so much for your help/advice.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 11, 2019, 7:33am UTC](https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230/4 "2019-04-11T07:33:08Z")

</div>

> [@tebriel](#):
>
> Can I rely on the allocations or is there a chance I could catch it between one finishing and the next starting?

There is no gap between the end of one relocation and the start of the next, but if there is a shard that cannot be relocated (e.g. it has an inconsistent set of allocation filters that are not satisfied on any node) then it will remain where it is, so I think a final check of `GET _cat/allocation/NODE_NAME` is a good idea even if using the cluster health API to wait.

---

<div class="post-metadata">

**Author:** ![tebriel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tebriel/32/44889_2.png) [@tebriel](https://discuss.elastic.co/u/tebriel)\
**Post date:** [April 11, 2019, 12:01pm UTC](https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230/5 "2019-04-11T12:01:45Z")

</div>

@DavidTurner makes sense. Thanks again!

---

<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:** [May 9, 2019, 12:01pm UTC](https://discuss.elastic.co/t/determine-node-is-safe-to-terminate/176230/6 "2019-05-09T12:01:46Z")

</div>

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