# How is sharding implemented?

**URL:** https://discuss.elastic.co/t/how-is-sharding-implemented/154716
**Category:** Elasticsearch
**Created:** [October 30, 2018, 7:12pm UTC](https://discuss.elastic.co/t/how-is-sharding-implemented/154716 "2018-10-30T19:12:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sm6405](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@sm6405](https://discuss.elastic.co/u/sm6405)
#### Post date: [October 30, 2018, 7:12pm UTC](https://discuss.elastic.co/t/how-is-sharding-implemented/154716/1 "2018-10-30T19:12:15Z")

</div>

I was wondering about the specific implementation of sharding within elasticsearch. I read many of the blog posts that state that the default value for sharding is 5 shards per index, however I was wondering about the process of how indexes are broken down into shards. Is it broken down by each **term** within a document, perhaps terms a-d will be sharded separately from d-z? Or by **document** where documents 1-2 will be sharded separately from documents 2-4? I’ve been trying to research this question to learn more about the underlying implementation, whether that's term sharding vs document sharding and have not had much luck. Any insight or references would be great! Thank you very much!

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [October 30, 2018, 7:27pm UTC](https://discuss.elastic.co/t/how-is-sharding-implemented/154716/2 "2018-10-30T19:27:04Z")

</div>

Entire documents are sharded, according to their document ID. The ID is hashed and then the hash modulo number of shards determines which primary shard receives the document.

Each shard maintains it's own term dictionary for frequencies, so searches are effectively shard-local and the results are merged at the coordinating node (with the assumption that doc frequencies are similar between all shards).

Hope this helps! 🙂

---

<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: [November 27, 2018, 7:27pm UTC](https://discuss.elastic.co/t/how-is-sharding-implemented/154716/3 "2018-11-27T19:27:06Z")

</div>

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