# Delete Index from Cluster State

**URL:** <https://discuss.elastic.co/t/delete-index-from-cluster-state/277343>\
**Category:** Elasticsearch\
**Created:** [June 29, 2021, 11:54am UTC](https://discuss.elastic.co/t/delete-index-from-cluster-state/277343 "2021-06-29T11:54:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daksh0225](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daksh0225/32/90336_2.png) [@daksh0225](https://discuss.elastic.co/u/daksh0225)\
**Post date:** [June 29, 2021, 11:54am UTC](https://discuss.elastic.co/t/delete-index-from-cluster-state/277343/1 "2021-06-29T11:54:52Z")

</div>

Hello!!  
I am trying to ensure that indices created during testing do not persist in elasticsearch when it is restarted. To achieve this, I have modiifed the **doStop()** function of _IndicesService_ in the following manner:

```auto
 if(index.getName().contains("global_"))
                        removeIndex(index, IndexRemovalReason.NO_LONGER_ASSIGNED, "shutdown");
                    else {
                        removeIndex(index, IndexRemovalReason.DELETED, "shutdown");

```

I am able to successfully delete the corresponding indices using this, but they are not getting removed from the cluster state. So next time when I start elasticsearch, it shows the following sort of message

```auto
recovered [1] indices into cluster_state

```

but in fact, the indices don't actually exist.

How do I update the cluster state as well?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 1, 2021, 2:02am UTC](https://discuss.elastic.co/t/delete-index-from-cluster-state/277343/2 "2021-07-01T02:02:05Z")

</div>

> [@daksh0225](#):
>
> I am able to successfully delete the corresponding indices using this, but they are not getting removed from the cluster state

Can you elaborate a little more on how you are identifying this?

---

<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 29, 2021, 2:02am UTC](https://discuss.elastic.co/t/delete-index-from-cluster-state/277343/3 "2021-07-29T02:02:39Z")

</div>

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