# How to obtain the list of \<forecast\_id\> associated to a \<job\_name\>

**URL:** <https://discuss.elastic.co/t/how-to-obtain-the-list-of-forecast-id-associated-to-a-job-name/276942>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-machine-learning\
**Created:** [June 24, 2021, 2:14pm UTC](https://discuss.elastic.co/t/how-to-obtain-the-list-of-forecast-id-associated-to-a-job-name/276942 "2021-06-24T14:14:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![StephaneB](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@StephaneB](https://discuss.elastic.co/u/StephaneB)\
**Post date:** [June 24, 2021, 2:14pm UTC](https://discuss.elastic.co/t/how-to-obtain-the-list-of-forecast-id-associated-to-a-job-name/276942/1 "2021-06-24T14:14:21Z")

</div>

Hi,  
I would like to get the list of all the \<forecast\_id\> associated to a specific \<job\_name\>.

I tried:

1. GET \_ml/anomaly\_detectors/\<job\_name\> but I don't obtain any information about associated forecast
2. GET \_ml/anomaly\_detectors/\<job\_name\>/\_stats but I obtain only the number and status of associated forecast (no \<forecast\_id\> list)

Any ideas?

---

<div class="post-metadata">

**Author:** ![BenTrent](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bentrent/32/33915_2.png) [@BenTrent](https://discuss.elastic.co/u/BenTrent)\
**Post date:** [June 24, 2021, 2:45pm UTC](https://discuss.elastic.co/t/how-to-obtain-the-list-of-forecast-id-associated-to-a-job-name/276942/2 "2021-06-24T14:45:45Z")

</div>

@StephaneB,

There is currently no API to provide this information. May I ask the reason for accessing it? I am wondering if we can provide a cleaner API to achieve what you are wanting.

If you 100% need to see the forecast IDs, the way to do so would be:

```auto
GET .ml-anomalies-*/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "result_type": "model_forecast_request_stats"
          }
        },
        {
          "term": {
            "job_id": <YOUR JOB ID>
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![StephaneB](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@StephaneB](https://discuss.elastic.co/u/StephaneB)\
**Post date:** [June 25, 2021, 8:28am UTC](https://discuss.elastic.co/t/how-to-obtain-the-list-of-forecast-id-associated-to-a-job-name/276942/3 "2021-06-25T08:28:15Z")

</div>

Hi @BenTrent ,

Thanks for your answer.

I'm working on alerting on forecast applied to some metrics (memory, cpu,..) and in order to have always the same forecast duration we have to create via API a new forecast every day. So we also need to remove the old forecast and for that, the only way is to get the \<forecast\_id\> at the new forecast creation and to store it in a file in order to delete it the day after. That's why it could be helpful to directly request via API the list of \<forecast\_id\> associated to a job and then to delete the \<forecast\_id\> created the previous day.

I also observed that if you create several forecast by using Kibana GUI, there is no way to delete a specific forecast (because this option is not available on GUI and the \<forecast\_id\> associated to each forecast is not displayed). You can only delete ALL the forecast by using the DELETE forecast API.

So, thanks a lot for the workaround you provided in your answer. It works fine!

---

<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:** [July 23, 2021, 8:29am UTC](https://discuss.elastic.co/t/how-to-obtain-the-list-of-forecast-id-associated-to-a-job-name/276942/4 "2021-07-23T08:29:10Z")

</div>

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