# Elasticsearch watcher to send Prediction data

**URL:** https://discuss.elastic.co/t/elasticsearch-watcher-to-send-prediction-data/154004
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [October 25, 2018, 12:55pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-to-send-prediction-data/154004 "2018-10-25T12:55:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kathir\_J](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@Kathir\_J](https://discuss.elastic.co/u/Kathir_J)
#### Post date: [October 25, 2018, 12:55pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-to-send-prediction-data/154004/1 "2018-10-25T12:55:44Z")

</div>

Elasticsearch watcher to send prediction data.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/5/05eb0877712bfa74bbcd4d603417ff6faf60d01f.png)

In this above screenshot, I have the prediction value as 32192.  
So, is it possible to alert the user (by using watcher) with the prediction value?

My watcher configuration is,

```
         {
              "range": {
                "anomaly_score": {
                  "gte": "30"
                }
              }
        }

```

1. Is it possible to include prediction value inside range?
2. Is it possible to include prediction value in slack text?  
"text": "Machine Learning Results - Object cache size is going to exceed threshold limit.\n Anomalies:\n{{#ctx.payload.hits.hits}}score={{\_source.anomaly\_score}} at time={{\_source.timestamp}}\n{{/ctx.payload.hits.hits}}"

If so, could you please let me know the syntax?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 25, 2018, 1:04pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-to-send-prediction-data/154004/2 "2018-10-25T13:04:52Z")

</div>

Hey,

I am not sure what you are referring to with the first question. Something you could do is to put the anomaly score in the watch metadata like

```auto
"metadata" : { "score" : "30" }

```

and then do this in your query

```auto
"range": { "anomaly_score": { "gte": "{{ctx.metadata.score}}" } }

```

and also refer to this in the slack message via `{{ctx.metadata.score}}`.

Your second assumption is correct, that this will return all the anomaly scors of the hits being returned.

Hope this helps!

--Alex

---

<div class="post-metadata">

### Author: ![Kathir\_J](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@Kathir\_J](https://discuss.elastic.co/u/Kathir_J)
#### Post date: [October 25, 2018, 1:26pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-to-send-prediction-data/154004/3 "2018-10-25T13:26:51Z")

</div>

Alright. Thanks for that. It clarifies my few other questions. 🙂

My use case,

In the screenshot I provided, When prediction value goes beyond 32000, I want to alert users along with the prediction value and prediction date in the alert text.

In watcher, I configured the alert text as

"text": "Machine Learning Results - Object cache size is going to exceed threshold limit.\n Anomalies:\n{{#ctx.payload.hits.hits}}score={{\_source.anomaly\_score}} at time={{\_source.timestamp}}\n{{/ctx.payload.hits.hits}}"

Alert should look something like,

As per prediction, Object cache size is going to be at \<prediction value\> on \<future date\>.

How do I include both \<prediction value\> and \<future date\>data in alert text.  
Is there anything like {{ctx.payload.hits.hits.0.prediction}}?

---

<div class="post-metadata">

### Author: ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)
#### Post date: [October 26, 2018, 4:08pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-to-send-prediction-data/154004/4 "2018-10-26T16:08:24Z")

</div>

For forecasts, you do NOT want to use `anomaly_score` as the thing you're reporting on. Instead, use `forecast_prediction `. Please reference this other thread:

> [@Export forecast data](https://discuss.elastic.co/t/export-forecast-data/124875/2):
>
> Hi Oscar, all forecast results are written back to the result index of the job, that is default the shared index: .ml-anomalies-shared but you can also use a dedicated index. Therefore you can access all results via search, e.g. GET .ml-anomalies-shared/\_search { "query": { "bool": { "filter": [ { "query\_string": { "query": "result\_type:model\_forecast" } }, { "query\_string": { "query": "job\_id:n1" …

---

<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: [November 23, 2018, 4:08pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-to-send-prediction-data/154004/5 "2018-11-23T16:08:27Z")

</div>

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