# Date-range based sharding

**URL:** <https://discuss.elastic.co/t/date-range-based-sharding/141908>\
**Category:** Elasticsearch\
**Created:** [July 27, 2018, 8:51am UTC](https://discuss.elastic.co/t/date-range-based-sharding/141908 "2018-07-27T08:51:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chits](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@chits](https://discuss.elastic.co/u/chits)\
**Post date:** [July 27, 2018, 8:51am UTC](https://discuss.elastic.co/t/date-range-based-sharding/141908/1 "2018-07-27T08:51:38Z")

</div>

Hi,

I want to implement custom, time stamp based sharding in my elastic search index,

for e.g: records with time \> t1 and \< t2 should go in one shard and records with time \>t2 and \< t3 should go in the second shard.

How can I achieve this?

---

<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:** [July 27, 2018, 9:08am UTC](https://discuss.elastic.co/t/date-range-based-sharding/141908/2 "2018-07-27T09:08:17Z")

</div>

What's the value in you doing this?

---

<div class="post-metadata">

**Author:** ![chits](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@chits](https://discuss.elastic.co/u/chits)\
**Post date:** [July 27, 2018, 9:19am UTC](https://discuss.elastic.co/t/date-range-based-sharding/141908/3 "2018-07-27T09:19:26Z")

</div>

To get better response time range queries

---

<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:** [July 27, 2018, 9:22am UTC](https://discuss.elastic.co/t/date-range-based-sharding/141908/4 "2018-07-27T09:22:20Z")

</div>

I don't think that will really do what you want to be honest.

If you want to filter things by that, why not add a step during ingest to add a flag that shows which timeframe it fits between (eg `"time_range": "t1-t2"` and `"time_range": "t2-t3"`), that you can then do a simple and efficient filter on.

---

<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:** [August 24, 2018, 9:22am UTC](https://discuss.elastic.co/t/date-range-based-sharding/141908/5 "2018-08-24T09:22:22Z")

</div>

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