elasticsearchelastic-stackelasticsearch-dslelasticsearch-opendistro

elasticsearch : how can i run hourly cron job to call _reindex api?


I would like how can i create & run cron job to call _reindex api every houre ?

I tried the following :

POST _reindex?wait_for_completion=false
{
  "trigger": {
    "schedule": {
      "interval": "1h"
    }
  },
  "source": {
    "index": "index_src"
  },
  "dest": {
    "index": "index_dest"
  }
}

But i got the following :

"reason" : "[2:5] [reindex] unknown field [trigger]"

any help would be really appriciated!


Solution

  • You can not do this only with the Elasticsearch API. A request to the reindex API will lead to an point in time action; it will not create a repeating task. As the error message states, there is no option to set a schedule in a reindex request.(see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html for all available settings).

    You would need to write a script (e.g. in bash if you are on a linux host) that periodically calls the reindex API. Another option would be to write a simple application that uses the Elasticsearch DSL in combination with a scheduling tool/framework like Spring Boot's @Scheduled-annotation.

    I hope I could help you.