# While searching how are shards picked for cluster with index.routing\_partition\_size

**URL:** <https://discuss.elastic.co/t/while-searching-how-are-shards-picked-for-cluster-with-index-routing-partition-size/357957>\
**Category:** Elasticsearch\
**Created:** [April 23, 2024, 3:03am UTC](https://discuss.elastic.co/t/while-searching-how-are-shards-picked-for-cluster-with-index-routing-partition-size/357957 "2024-04-23T03:03:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktech007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ktech007/32/124751_2.png) [@ktech007](https://discuss.elastic.co/u/ktech007)\
**Post date:** [April 23, 2024, 3:03am UTC](https://discuss.elastic.co/t/while-searching-how-are-shards-picked-for-cluster-with-index-routing-partition-size/357957/1 "2024-04-23T03:03:54Z")

</div>

Let's say my cluster is set up with `index.routing_partition_size` of 20. For a routing key `abc`, it can then route documents to max 20 shards. Here is a scenario:

- Suppose a document comes with routing key `abc` and it is routed to shard 10 out of 100 shards the index has. This is the first document that lands on that shard.
- While searching, we pass routing `abc`.

Two questions:

- How does it determine what shards to pick? Is the list of shards pre-calculated based on the routing key?
- If the routes are sort of dynamically added to some list as the documents are added, is this list cached and then refreshed? Is there a delay? For example: I search for the above-mentioned document. Is there a scenario where it may not be returned because that shard is not in this cached table?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 23, 2024, 6:26am UTC](https://discuss.elastic.co/t/while-searching-how-are-shards-picked-for-cluster-with-index-routing-partition-size/357957/2 "2024-04-23T06:26:26Z")

</div>

> [@ktech007](#):
>
> How does it determine what shards to pick? Is the list of shards pre-calculated based on the routing key?

Yes, the shard determination is deterministic based on the routing key and the document ID. The calculation is [described here](https://www.elastic.co/guide/en/elasticsearch/reference/8.13/mapping-routing-field.html#routing-index-partition).
