# Schedule a Job in Elasticsearch

**URL:** <https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032>\
**Category:** Elasticsearch\
**Created:** [February 22, 2021, 7:17am UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032 "2021-02-22T07:17:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gruselglatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gruselglatz/32/42675_2.png) [@gruselglatz](https://discuss.elastic.co/u/gruselglatz)\
**Post date:** [February 22, 2021, 7:17am UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/1 "2021-02-22T07:17:20Z")

</div>

Hi,  
is it possible to schedule a job in elasticsearch and save it?

My requirements are that the team only wants to keep certain messages after xy days to reduce the storage capacity.

Can i realize it with rollover, ilm? I only thought about reindex and then delete the old index. But I didnt found a way to schedule jobs/tasks or store it somewhere. And we dont want to create another container which only runs this one job via the api.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 22, 2021, 7:53am UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/2 "2021-02-22T07:53:45Z")

</div>

I believe that ILM is designed for that. (Index Lifecycle Management)

---

<div class="post-metadata">

**Author:** ![gruselglatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gruselglatz/32/42675_2.png) [@gruselglatz](https://discuss.elastic.co/u/gruselglatz)\
**Post date:** [February 22, 2021, 9:02am UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/3 "2021-02-22T09:02:09Z")

</div>

I use ILM but i didnt find a way to give ILM more instructions to only delete xy messages and keep others.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 22, 2021, 10:29am UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/4 "2021-02-22T10:29:08Z")

</div>

If you are using time based indices, which is the recommendation for this kind of use case, then it should be easy to configure ILM to move old indices to cold or delete phase...

---

<div class="post-metadata">

**Author:** ![gruselglatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gruselglatz/32/42675_2.png) [@gruselglatz](https://discuss.elastic.co/u/gruselglatz)\
**Post date:** [February 22, 2021, 11:47am UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/5 "2021-02-22T11:47:03Z")

</div>

Yes this is pretty easy, but i want to delete only specific messages from indices not the complete index.

---

<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:** [February 22, 2021, 12:02pm UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/6 "2021-02-22T12:02:56Z")

</div>

Deleting documents from indices is very expensive and inefficient compared to deleting complete indices so is not recommended nor supported by ILM. You will therefore need to set up a cron job or similar to periodically run a delete by query.

---

<div class="post-metadata">

**Author:** ![gruselglatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gruselglatz/32/42675_2.png) [@gruselglatz](https://discuss.elastic.co/u/gruselglatz)\
**Post date:** [February 22, 2021, 12:17pm UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/7 "2021-02-22T12:17:34Z")

</div>

Yeah i know this too, this is why I thought if i can maybe reindex only the wanted messages into a new index and delete the old one with some form of job in elasticsearch.

It would be a reindex and one delete job. or only the reindex and delete via ILM. Is this possible to store some job somewhere like [GitHub - opendistro-for-elasticsearch/job-scheduler: 🕓 Open Distro for Elasticsearch Job Scheduler](https://github.com/opendistro-for-elasticsearch/job-scheduler) ?

---

<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:** [February 22, 2021, 12:42pm UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/8 "2021-02-22T12:42:34Z")

</div>

For that you probably need to ask in the OpenDistro forum.

---

<div class="post-metadata">

**Author:** ![gruselglatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gruselglatz/32/42675_2.png) [@gruselglatz](https://discuss.elastic.co/u/gruselglatz)\
**Post date:** [February 22, 2021, 12:45pm UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/9 "2021-02-22T12:45:00Z")

</div>

@Christian_Dahlqvist I know i dont get infos about it here, but i used it as a comparison.... because i didnt found anything like it. And I am not interested in the opendistro elasticsearch fight...

Is there a function in elasticsearch to store tasks which are executed in a periodic way?

---

<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:** [February 22, 2021, 12:56pm UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/10 "2021-02-22T12:56:32Z")

</div>

Not that I know of.

---

<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:** [March 22, 2021, 12:56pm UTC](https://discuss.elastic.co/t/schedule-a-job-in-elasticsearch/265032/11 "2021-03-22T12:56:49Z")

</div>

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