# Allocate specific shards on specific nodes

**URL:** <https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950>\
**Category:** Elasticsearch\
**Created:** [March 31, 2016, 2:02pm UTC](https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950 "2016-03-31T14:02:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayme/32/6008_2.png) [@Jayme](https://discuss.elastic.co/u/Jayme)\
**Post date:** [March 31, 2016, 2:02pm UTC](https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950/1 "2016-03-31T14:02:40Z")

</div>

Hi,  
given that I have a cluster with for example 8 nodes  
elastic1 -\> elastic8  
and I create an index with 8 shards, is there a way to enforce the following from the start:  
shard 1 should be on elastic1,  
shard 2 on elastic2,  
shard 3 on elastic3  
..  
shard 8 on elastic8.

I know you can use the \_reroute api afterwards based on how elastic routed the shards initially but I would like to have something where I can tell elasticsearch to do this from the start.

I need this because I have a plugin that keeps a state in memory for certain documents,  
and I need to know for sure if a new index is made on what node a certain shard is on.(needs to be same for new indexes)

---

<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:** [April 1, 2016, 6:15am UTC](https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950/2 "2016-04-01T06:15:44Z")

</div>

You cannot do this automatically, and you don't want to.

> [@Jayme](#):
>
> I need this because I have a plugin that keeps a state in memory for certain documents, and I need to know for sure if a new index is made on what node a certain shard is on.(needs to be same for new indexes)

This seems extremely dangerous.

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [April 1, 2016, 10:42am UTC](https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950/3 "2016-04-01T10:42:46Z")

</div>

There are ways to influence shard allocation, for instance based on racks or how beefy machines are. That said I am not sure these apply to your case. Also, I don't follow why you would need to do that. You mentioned that you have a plugin that needs to know and maybe that is the root of the problem. Maybe you can explain a bit more about the plugin and the reason behind this requirement though.

---

<div class="post-metadata">

**Author:** ![Jayme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayme/32/6008_2.png) [@Jayme](https://discuss.elastic.co/u/Jayme)\
**Post date:** [April 2, 2016, 12:47pm UTC](https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950/4 "2016-04-02T12:47:53Z")

</div>

I still think there are more advanced use cases where you want to have full control over allocations.

For example if you start with 8 equal servers with x amount of (smaller) indices having each a different amount of shards. If you would then create a new larger index that gets searched a lot with 8 shards, it could be that 2 shards are assigned to one node and that one node would bring down the search performance. Because you're not using a well balanced index over all nodes.

I think it's a limitation of the current index create API if you're able to do the allocation with the reroute api immediately afterwards. Either you don't expose the \_reroute api or have similar functionality available from the start in the create api.

The plugin is my own plugin, it tracks usage of certain documents that I need in ordering (score changes based on usage). It needs to be fast and expire after a while. I can't use an attribute in the index as this would need disk acces and recreation of the document each time the attribute gets updated. I use a fixed guava java cache, that expires after x amount of time so it will never expose a threat to the server memory.

Anyways I've managed to get it working using the \_reroute api now.

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [April 4, 2016, 8:36am UTC](https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950/5 "2016-04-04T08:36:57Z")

</div>

Did you have a look at [shard allocation filtering](https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-allocation-filtering.html)? Sounds like it would help in your case, and would be much less manual that using the reroute api.

Cheers  
Luca

---

<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 5, 2017, 11:02pm UTC](https://discuss.elastic.co/t/allocate-specific-shards-on-specific-nodes/45950/6 "2017-07-05T23:02:41Z")

</div>


