# Shrink API and Relocation of Shards

**URL:** https://discuss.elastic.co/t/shrink-api-and-relocation-of-shards/146509
**Category:** Elasticsearch
**Created:** [August 29, 2018, 10:20am UTC](https://discuss.elastic.co/t/shrink-api-and-relocation-of-shards/146509 "2018-08-29T10:20:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Edouard\_Fazenda](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Edouard\_Fazenda](https://discuss.elastic.co/u/Edouard_Fazenda)
#### Post date: [August 29, 2018, 10:20am UTC](https://discuss.elastic.co/t/shrink-api-and-relocation-of-shards/146509/1 "2018-08-29T10:20:33Z")

</div>

Dear Community,

I am in the process of performing a shrink on indices in order to reduce the number of shards from 5 to 1 , i choose to test on my cluster on 1 index named "logstash-ssh-\*'

So i followed the documentation form elasticsearch : [https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-shrink-index.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-shrink-index.html)

By putting index in read-only and relocating the shards to one node in order to have the primary and replica on the same elasticsearch node.

```
PUT /logstash-ssh-*/_settings
{
  "settings": {
    "index.routing.allocation.require._host": "elastic-01",
    "index.blocks.write": true 
  }
}

```

If I check if the operation has been taken by elasticsearch it seems yes :

```
"logstash-ssh-2018.05.15": {
    "settings": {
        "index": {
            "blocks": {
                "write": "true"
            },
            "creation_date": "1526342499442",
            "number_of_replicas": "1",
            "number_of_shards": "5",
            "provided_name": "logstash-ssh-2018.05.15",
            "refresh_interval": "5s",
            "routing": {
                "allocation": {
                    "require": {
                        "_host": "",
                        "_ip": "",
                        "_name": "elastic-01"
                    }
                }
            },
            "uuid": "Lq38GrBySk6qO2RNRa8Clw",
            "version": {
                "created": "6020399"
            }
        }
    }
},
.....

```

But when I check if somes shards are relocating , it seems not

```
 curl -s 'http://elastic-01.domain.local:9200/_cat/shards?v' | fgrep RELO
<Empty output>

```

And if i check the shards by filtering from the index pattern logstash-ssh-\*, it seems that nothing happen , the shards are still shared with my both elasticsearch nodes.

Did i miss something , is there are some parameter that stuck relocating of shards at the cluster level ?

I'm running the 6.2.3 Elasticsearch version on my cluster.

Thanks in advance for your help.

Best Regards, Edouard Fazenda.

---

<div class="post-metadata">

### Author: ![Edouard\_Fazenda](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Edouard\_Fazenda](https://discuss.elastic.co/u/Edouard_Fazenda)
#### Post date: [August 30, 2018, 8:53am UTC](https://discuss.elastic.co/t/shrink-api-and-relocation-of-shards/146509/2 "2018-08-30T08:53:27Z")

</div>

Hello 🙂

Is up this topic in case someone can help me.

Thanks 🙂

---

<div class="post-metadata">

### Author: ![cdekker](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cdekker](https://discuss.elastic.co/u/cdekker)
#### Post date: [August 30, 2018, 3:33pm UTC](https://discuss.elastic.co/t/shrink-api-and-relocation-of-shards/146509/3 "2018-08-30T15:33:59Z")

</div>

> [@Edouard\_Fazenda](#):
>
> By putting index in read-only and relocating the shards to one node in order to have the primary and replica on the same elasticsearch node.

Elasticsearch will never put a primary and replica of a shard on the same node. If you have 2 nodes and `number_of_replicas` set to 1 each node has the full set of shards available. Nothing will ever be relocated in this scenario.

Did you run the `_shrink` command? Any error is generally pretty descriptive of what goes wrong.

If that doesn't work, try setting the number of replicas to 0 before running \_shrink.

---

<div class="post-metadata">

### Author: ![Edouard\_Fazenda](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Edouard\_Fazenda](https://discuss.elastic.co/u/Edouard_Fazenda)
#### Post date: [September 3, 2018, 1:56pm UTC](https://discuss.elastic.co/t/shrink-api-and-relocation-of-shards/146509/4 "2018-09-03T13:56:07Z")

</div>

Thanks for the help , yes I run the \_shrink command via curator and i made a bash script to add an alias with the old index name.

It's working well.

Have a nice day.

---

<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: [October 1, 2018, 1:56pm UTC](https://discuss.elastic.co/t/shrink-api-and-relocation-of-shards/146509/5 "2018-10-01T13:56:33Z")

</div>

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