# How to shrink an index spread over multiple nodes

**URL:** https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814
**Category:** Elasticsearch
**Created:** [July 19, 2020, 8:58pm UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814 "2020-07-19T20:58:27Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Prash7](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@Prash7](https://discuss.elastic.co/u/Prash7)
#### Post date: [July 19, 2020, 8:58pm UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/1 "2020-07-19T20:58:27Z")

</div>

Hey Team,

How do i go about shrinking an index, which has shards over multiple nodes ?  
I keep getting this error

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[pronto-g3-1577817661-3-1463179-pronto][10.174.157.164:9300][indices:admin/resize]"
      }
    ],
    "type": "illegal_state_exception",
    "reason": "index time_logs_data_2020_06_16 must have all shards allocated on the same node to shrink index"
  },
  "status": 500
}

```

I would also like to explore if there's any way of enforcing future indices to be created on the same node, so i can shrink them later on when they become read only. Thanks in advance!

---

<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 20, 2020, 2:13am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/2 "2020-07-20T02:13:25Z")

</div>

> **[Shrink index API | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shrink-index.html#shrink-index-api-prereqs)**

> Before you can shrink an index:
> 
> - The index must be read-only.
> - A copy of every shard in the index must reside on the same node.
> - The [cluster health](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html) status must be green.

> [@Prash7](#):
>
> I would also like to explore if there's any way of enforcing future indices to be created on the same node, so i can shrink them later on when they become read only

Check out this part of [ILM](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-allocate.html).

---

<div class="post-metadata">

### Author: ![Steve\_Mushero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steve_mushero/32/22441_2.png) [@Steve\_Mushero](https://discuss.elastic.co/u/Steve_Mushero)
#### Post date: [July 20, 2020, 6:19am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/3 "2020-07-20T06:19:29Z")

</div>

Wonder why cluster has to be green ... makes sense for index to be green, I guess - though what about replicas? Ah, says the node only needs a copy of each shard, not all the shards (can be some replicas, though hard to do that in practice).

Note that doc is really not right as says the API call "three conditions can be achieved" - but one condition is green cluster; pretty sure no API call can make a cluster green 😉

---

<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 20, 2020, 6:24am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/4 "2020-07-20T06:24:42Z")

</div>

> [@Steve\_Mushero](#):
>
> Note that doc is really not right as says the API call "three conditions can be achieved" - but one condition is green cluster; pretty sure no API call can make a cluster green 😉

You'd normally drop the replica set before reallocating the shards, shrinking, then add them back.

---

<div class="post-metadata">

### Author: ![Steve\_Mushero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steve_mushero/32/22441_2.png) [@Steve\_Mushero](https://discuss.elastic.co/u/Steve_Mushero)
#### Post date: [July 20, 2020, 6:43am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/5 "2020-07-20T06:43:04Z")

</div>

Makes sense; surprised not mentioned in that somewhat confusing doc page.

---

<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 21, 2020, 1:43am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/6 "2020-07-21T01:43:13Z")

</div>

I would encourage you to raise a docs issue on GitHub to get it added if you'd like to see it there.

---

<div class="post-metadata">

### Author: ![Steve\_Mushero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steve_mushero/32/22441_2.png) [@Steve\_Mushero](https://discuss.elastic.co/u/Steve_Mushero)
#### Post date: [July 21, 2020, 2:48am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/7 "2020-07-21T02:48:50Z")

</div>

> [@warkolm](#):
>
> You'd normally drop the replica set before reallocating the shards, shrinking, then add them back.

Thanks - is there a link/dock on best way to do that; seen the awesome Github doc repo, but not sure how to raise issue on specific page (vs. the 'project').

---

<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 21, 2020, 5:09am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/8 "2020-07-21T05:09:40Z")

</div>

The docs are part of each product, so raise a feature request - [https://github.com/elastic/elasticsearch/issues/new/choose](https://github.com/elastic/elasticsearch/issues/new/choose)

---

<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: [August 18, 2020, 5:09am UTC](https://discuss.elastic.co/t/how-to-shrink-an-index-spread-over-multiple-nodes/241814/9 "2020-08-18T05:09:43Z")

</div>

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