# Rollover Index based on timestamp field

**URL:** https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229
**Category:** Elasticsearch
**Created:** [July 25, 2019, 11:14am UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229 "2019-07-25T11:14:30Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Jayabal\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayabal_k/32/41905_2.png) [@Jayabal\_K](https://discuss.elastic.co/u/Jayabal_K)
#### Post date: [July 25, 2019, 11:14am UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/1 "2019-07-25T11:14:31Z")

</div>

I need to rollover the index on daily basis. currently I am using curator rollover action (max\_size: 1d) and my index pattern : test-YYYY.MM.DD-1. my cronjob is running every hour once.

Our scenario: Index created at 4:30 and data continuously ingesting, I need rollover happen at next day 00:00 but rollover happens after 4:30 hrs next day. Due to this next day (2019-07-25) data ingested in previous day index(test-2019-07-24).

How could I ingest the data based on the timestamp 25th day data to 25th day index?  
Consider document consists of timestamp filed in it.

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [July 25, 2019, 12:34pm UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/2 "2019-07-25T12:34:00Z")

</div>

> [@Jayabal\_K](#):
>
> I need to rollover the index on daily basis.
> 
> I need rollover happen at next day 00:00

Why? What is the use case that requires this?

---

<div class="post-metadata">

### Author: ![Jayabal\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayabal_k/32/41905_2.png) [@Jayabal\_K](https://discuss.elastic.co/u/Jayabal_K)
#### Post date: [August 7, 2019, 10:47am UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/3 "2019-08-07T10:47:13Z")

</div>

Our use case is to delete the data older than n days, For that I am planning to do day based index(daily rollover using curator rollover job). Actually I want 25th day data in 25 day index only and so on.

Also I would like know how curator calculates the age of the index?  
Please explain.

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [August 7, 2019, 4:54pm UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/4 "2019-08-07T16:54:52Z")

</div>

Why, when Elasticsearch can query multiple indices at once, and still limit data to a specific date range? This is needlessly complex. It's not a big deal to still do rollover indices—even daily ones at UTC 0:00—and just delete them on day 26, so day 25 is still present.

It's terribly complex to try to get every single event into Elasticsearch on precisely the correct date index if you're using anything other that UTC timing. That's why I ask.

---

<div class="post-metadata">

### Author: ![Jayabal\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayabal_k/32/41905_2.png) [@Jayabal\_K](https://discuss.elastic.co/u/Jayabal_K)
#### Post date: [August 9, 2019, 6:00am UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/5 "2019-08-09T06:00:02Z")

</div>

If we do rollover daily once, we can have multiple indices(test-day1,test-day2,test3....). If we need to query data for last one day only, then there is no point to query all the indices (test\*). If we have one day data in a specific index(day1 data ==\> test-day1). Then it will easy to query that one index alone(test-day1) instead of querying all the index for last one data.

Also if one index may contain some second day means, while deleting indices we will loose the data.  
In order to avoid the above scenarios I need one day data present in one index.

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [August 9, 2019, 6:05am UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/6 "2019-08-09T06:05:54Z")

</div>

I still wouldn't recommend that approach, due to the complexity involved. From where I sit, you're adding a lot of complexity on the ingest side to save yourself a tiny bit of work on the query side.

But if that is how you want to roll, go for it.

---

<div class="post-metadata">

### Author: ![Jayabal\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayabal_k/32/41905_2.png) [@Jayabal\_K](https://discuss.elastic.co/u/Jayabal_K)
#### Post date: [August 9, 2019, 6:10am UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/7 "2019-08-09T06:10:24Z")

</div>

I understand your point here, If we do query all the index at one time, how could be performance of query?

Also I have little concern that we will some data while deleting index. Is there any to over come this issue?

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [August 9, 2019, 2:54pm UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/8 "2019-08-09T14:54:50Z")

</div>

> [@Jayabal\_K](#):
>
> If we do query all the index at one time, how could be performance of query?

Querying all indices isn't necessarily a bother with updates to Elasticsearch since 6.0. Also, the easiest thing is to add a date range filter to your query that limits it to the desired time frame. Filters are exceptionally fast, and a document either is, or is not within a time range.

> [@Jayabal\_K](#):
>
> Also I have little concern that we will [lose] some data while deleting index. Is there any to over come this issue?

Don't delete an index until every part of the index is acceptable to delete. Curator provides an extension to the [`age` filter](https://www.elastic.co/guide/en/elasticsearch/client/curator/5.7/filtertype_age.html) that can calculate the age of the oldest or youngest/newest document in an index. This is called [`field_stats`](https://www.elastic.co/guide/en/elasticsearch/client/curator/5.7/filtertype_age.html#_field_stats_based_ages), and was originally based on the Elasticsearch 5.x field stats query. It now simply performs an aggregation for these values. Using this allows you to ensure an index will not be deleted until its youngest document is safely within your desired threshold.

---

<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: [September 6, 2019, 2:54pm UTC](https://discuss.elastic.co/t/rollover-index-based-on-timestamp-field/192229/9 "2019-09-06T14:54:52Z")

</div>

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