# Getting informed of moving shards in the cluster

**URL:** <https://discuss.elastic.co/t/getting-informed-of-moving-shards-in-the-cluster/9223>\
**Category:** Elasticsearch\
**Created:** [October 3, 2012, 9:43am UTC](https://discuss.elastic.co/t/getting-informed-of-moving-shards-in-the-cluster/9223 "2012-10-03T09:43:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 3, 2012, 9:43am UTC](https://discuss.elastic.co/t/getting-informed-of-moving-shards-in-the-cluster/9223/1 "2012-10-03T09:43:07Z")

</div>

Hi,

is there any possibility to get informed, when a shard is moved from  
one instance to another or when it is being deleted? I'd like to free  
up some in-memory resources in case that happens in my  
AbstractIndexShardComponent.

Regards, Alexander

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [October 3, 2012, 4:14pm UTC](https://discuss.elastic.co/t/getting-informed-of-moving-shards-in-the-cluster/9223/2 "2012-10-03T16:14:46Z")

</div>

Alexander,

For the former, you probably can poll the cluster state for reallocating  
shards. Not very efficient, but since shard reallocation can take some time  
for non-trivial indices (large shards), the polling interval can be large.

Deletions would be tough. When exactly is a shard deleted in Elasticsearch?  
The only scenario I can think of is during a reallocation (copy and  
deleted) and when the numbers of replicas is reduced (which is under user  
control).

--  
Ivan

On Wed, Oct 3, 2012 at 2:43 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hi,
> 
> is there any possibility to get informed, when a shard is moved from  
> one instance to another or when it is being deleted? I'd like to free  
> up some in-memory resources in case that happens in my  
> AbstractIndexShardComponent.
> 
> Regards, Alexander
> 
> --

--

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [October 3, 2012, 8:21pm UTC](https://discuss.elastic.co/t/getting-informed-of-moving-shards-in-the-cluster/9223/3 "2012-10-03T20:21:09Z")

</div>

Hi Alexander,

I think I asked about this once on the ML and I think I subsequently opened  
an issue on Github.

## Otis

Search Analytics - [Cloud Monitoring Tools & Services | Sematext](http://sematext.com/search-analytics/index.html)  
Performance Monitoring - [http://sematext.com/spm/index.htm](http://sematext.com/spm/index.htm)

On Wednesday, October 3, 2012 5:43:15 AM UTC-4, Alexander Reelsen wrote:

> Hi,
> 
> is there any possibility to get informed, when a shard is moved from  
> one instance to another or when it is being deleted? I'd like to free  
> up some in-memory resources in case that happens in my  
> AbstractIndexShardComponent.
> 
> Regards, Alexander

--

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 5, 2012, 3:56pm UTC](https://discuss.elastic.co/t/getting-informed-of-moving-shards-in-the-cluster/9223/4 "2012-10-05T15:56:18Z")

</div>

Hi

On Wed, Oct 3, 2012 at 10:21 PM, Otis Gospodnetic  
[otis.gospodnetic@gmail.com](mailto:otis.gospodnetic@gmail.com) wrote:

> I think I asked about this once on the ML and I think I subsequently opened  
> an issue on Github.  
> Hm. What about IndicesLifecycle.Listener.beforeIndexShardClosed() -  
> which seems to do what I just want. It even handles deletes  
> differently.

Calling this should be enough:  
indicesService.indicesLifecycle().addListener(new Listener() { /\*  
yadayadayada \*/ })

there is also a shardRoutingChanged() method... so I can catch deleted  
and shard moves (which in the end will likely also issue an delete on  
the shard moved, everything fine for me).

--Alexander

--

---

<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, 3:09am UTC](https://discuss.elastic.co/t/getting-informed-of-moving-shards-in-the-cluster/9223/5 "2017-07-06T03:09:59Z")

</div>


