# How to calculate the shard id/name for given routing string?

**URL:** <https://discuss.elastic.co/t/how-to-calculate-the-shard-id-name-for-given-routing-string/59529>\
**Category:** Elasticsearch\
**Created:** [September 1, 2016, 10:14am UTC](https://discuss.elastic.co/t/how-to-calculate-the-shard-id-name-for-given-routing-string/59529 "2016-09-01T10:14:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gacio](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gacio](https://discuss.elastic.co/u/gacio)\
**Post date:** [September 1, 2016, 10:14am UTC](https://discuss.elastic.co/t/how-to-calculate-the-shard-id-name-for-given-routing-string/59529/1 "2016-09-01T10:14:37Z")

</div>

I want to get the value of the shard ID/Name for a given routing string.  
Say I got two shards data-1 and data-2 and routing string route1.

How can I simply calculate which shard ID/Name will be the result if the ES 2 routing algorithm?

---

<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 1, 2016, 2:00pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-shard-id-name-for-given-routing-string/59529/2 "2016-09-01T14:00:04Z")

</div>

Can you explain why exactly you need this information?

Not sure if you've seen it, maybe [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html) helps with your question.

---

<div class="post-metadata">

**Author:** ![gacio](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gacio](https://discuss.elastic.co/u/gacio)\
**Post date:** [September 1, 2016, 2:11pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-shard-id-name-for-given-routing-string/59529/3 "2016-09-01T14:11:25Z")

</div>

Thank you for responding.  
I need to determine to which shard is the document routed and which node carries this shard. This is required by my data flow security. Thus I need to have full information form document routing and shared allocation filtering.

---

<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 1, 2016, 2:29pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-shard-id-name-for-given-routing-string/59529/4 "2016-09-01T14:29:24Z")

</div>

The documentation I linked above has the formula for computing the id of the targeted shard. However when talking about security you might want to check out [https://www.elastic.co/guide/en/shield/current/index.html](https://www.elastic.co/guide/en/shield/current/index.html)

---

<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:23pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-shard-id-name-for-given-routing-string/59529/5 "2017-07-05T22:23:14Z")

</div>


