# \[Help\] Understanding routing to an index partition

**URL:** <https://discuss.elastic.co/t/help-understanding-routing-to-an-index-partition/293812>\
**Category:** Elasticsearch\
**Created:** [January 8, 2022, 8:03pm UTC](https://discuss.elastic.co/t/help-understanding-routing-to-an-index-partition/293812 "2022-01-08T20:03:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radaeld](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Radaeld](https://discuss.elastic.co/u/Radaeld)\
**Post date:** [January 8, 2022, 8:03pm UTC](https://discuss.elastic.co/t/help-understanding-routing-to-an-index-partition/293812/1 "2022-01-08T20:03:38Z")

</div>

Hey all  
I have some questions regarding routing\_partition\_size field.  
Not sure but upon reading the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html#routing-index-partition) , this is what i understood:

By default, using a routing key will access only 1 primary shard, for indexing document and fetching.  
When specifying the routing\_partition\_size, the routing key will now access the number of shards specified in this field.

I tried to test this. I created an index with 6 primary shards only and specified routing\_partition\_size with a value of 4.

```auto
curl -X PUT localhost:9200/my-index-000000 -d '{ "settings": { "number_of_shards": 6 , "number_of_replicas": 0, "index.routing_partition_size": 4}, "mappings": {"_routing": {"required": true}}}' -H "Content-Ty
pe: application/json"

```

So in theory when indexing documents with a given key it should be distributed among 4 priamry shards, or i belived so. But i tried to index 100k documents and they all went to the same shard

```auto
for i in {0..100000}; do curl -X POST localhost:9200/my-index-000000/_doc?routing=key1 -d '{ "data": "something" }' -H "Content-Type: application/json"; done

```

```auto
curl -X GET localhost:9200/_cat/shards?v

my-index-000000 2 p STARTED 0 226b 172.20.0.4 es02
my-index-000000 5 p STARTED 0 226b 172.20.0.4 es02
my-index-000000 3 p STARTED 0 226b 172.20.0.2 es03
my-index-000000 1 p STARTED 0 226b 172.20.0.3 es01
my-index-000000 4 p STARTED 0 226b 172.20.0.3 es01
my-index-000000 0 p STARTED 100001 2.7mb 172.20.0.2 es03

```

Am i missing something, or did i understood this wrong?

Thanks in advance for the help  
And happy new year 🙂

---

<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:** [January 9, 2022, 11:15pm UTC](https://discuss.elastic.co/t/help-understanding-routing-to-an-index-partition/293812/2 "2022-01-09T23:15:46Z")

</div>

Welcome to our community! 😃

I don't know this in detail, but my reading of the docs suggest that it'd work like this when indexing;

1. From your 6 shards, only use 4
2. Then index into one of those 4
3. From your 6 shards, only use 4, but as you're looking at the entire 6 shards again, then it's possible that it'll pick ones that weren't previously used
4. Then index into one of those 4
5. and so on

Basically, just because you set the partition size to less than the total shard count, doesn't mean the shards that will be picked for indexing will _always be the same_.

**But** that's an educated guess based on my use of the product for a while, so I don't know the feature or the code down to a level to be able to state that as actual fact. Hopefully someone that does know can stop in and comment either way so we can both learn 🙂

---

<div class="post-metadata">

**Author:** ![Radaeld](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Radaeld](https://discuss.elastic.co/u/Radaeld)\
**Post date:** [January 11, 2022, 9:34pm UTC](https://discuss.elastic.co/t/help-understanding-routing-to-an-index-partition/293812/3 "2022-01-11T21:34:10Z")

</div>

Hey @warkolm  
Yup it seems to be as i was thinking.

It seems there is a bug issue going on [github](https://github.com/elastic/elasticsearch/issues/48863). This explains why the 100k documents went all to the same shard 😅

Thanks for the answer and help 🙂

---

<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:** [February 8, 2022, 9:34pm UTC](https://discuss.elastic.co/t/help-understanding-routing-to-an-index-partition/293812/4 "2022-02-08T21:34:31Z")

</div>

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