# Elasticsearch how to figure out the shard number with the specified routing?

**URL:** <https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842>\
**Category:** Elasticsearch\
**Created:** [September 19, 2016, 7:47am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842 "2016-09-19T07:47:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hex2tan](https://avatars.discourse-cdn.com/v4/letter/h/d2c977/32.png) [@hex2tan](https://discuss.elastic.co/u/hex2tan)\
**Post date:** [September 19, 2016, 7:47am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842/1 "2016-09-19T07:47:22Z")

</div>

eg: I have a index with 5 primary shard, when I query/insert a document with routing. How can I figure out the shard number? [According to the document](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html) the formula is: `shard_num = hash(_routing) % num_primary_shards`.Certainly, I can read the source code of the hash function, but I want to know there is any plugins or any easy way to figure out the shard number when I specify a routing.  
THX in advance.

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [September 19, 2016, 8:18am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842/2 "2016-09-19T08:18:10Z")

</div>

I don't know of any plugins at the top of my head.

May I ask what's your use case for needing to figure this out?

Isabel

---

<div class="post-metadata">

**Author:** ![hex2tan](https://avatars.discourse-cdn.com/v4/letter/h/d2c977/32.png) [@hex2tan](https://discuss.elastic.co/u/hex2tan)\
**Post date:** [September 19, 2016, 1:07pm UTC](https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842/3 "2016-09-19T13:07:25Z")

</div>

Thanks for your reply.  
I have some data, a hundred million entries everyday. I pan to store them in ES with the routing(the date of day, like 20160917).So I want to figure out how many shards I need to set for the index of month and guarantee there is no unused shards.Of course, the empty shard not affect any stuff, and I am curious about it, besides I am a OCD:joy:.  
Maybe, I have to read the fucking source code finally.

---

<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:** [September 19, 2016, 1:13pm UTC](https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842/4 "2016-09-19T13:13:10Z")

</div>

Have you considered using [time-based indices](https://www.elastic.co/guide/en/elasticsearch/guide/current/time-based.html)?

---

<div class="post-metadata">

**Author:** ![hex2tan](https://avatars.discourse-cdn.com/v4/letter/h/d2c977/32.png) [@hex2tan](https://discuss.elastic.co/u/hex2tan)\
**Post date:** [September 20, 2016, 1:22am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842/5 "2016-09-20T01:22:12Z")

</div>

THX guy.  
I have already done so.

---

<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, 10:18pm UTC](https://discuss.elastic.co/t/elasticsearch-how-to-figure-out-the-shard-number-with-the-specified-routing/60842/6 "2017-07-05T22:18:59Z")

</div>


