How to export forecast data into a destination index

Hello,

I'm currently using API to create job, datafeed and associated forecast in order to determine if some predicted values will exceed a specific threshold in the next weeks:

  • if no value exceeds the threshold then I delete the job (with its associated datafeed and forecast)
  • if some values exceed the threshold then I would like to export all the forecast documents into a specific index before deleting the job (with its associated datafeed and forecast).

I can retreive all the forecast data by using the following search and then copy all the forecast documents in a destination index (with a loop on hits).

GET .ml-anomalies*/_search
{
  "query": {
    "bool" :{
      "filter": [
        { 
          "query_string":{
            "query": "result_type:model_forecast",
            "analyze_wildcard": true
          }
        },
        {"term": { "job_id": "job_on_device1"}},
        {"term": { "forecast_id": "Gwn4wnoB0F2uUBpmgO6V"}}]
    }
  }
}

But, is there another way to export forecast documents to a specific index?