# Check Forecast accuracy with scripted field

**URL:** https://discuss.elastic.co/t/check-forecast-accuracy-with-scripted-field/324650
**Category:** Kibana
**Tags:** elastic-stack-machine-learning
**Created:** [February 3, 2023, 1:31pm UTC](https://discuss.elastic.co/t/check-forecast-accuracy-with-scripted-field/324650 "2023-02-03T13:31:06Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)
#### Post date: [February 10, 2023, 4:23pm UTC](https://discuss.elastic.co/t/check-forecast-accuracy-with-scripted-field/324650/4 "2023-02-10T16:23:20Z")

</div>

Hmm, so I think you should only need one transform. In that transform you should use your "real" data index, then add a lookup runtime field that queries your "forecast" index.

Maybe something like;

```auto
PUT _transform/asdf
{
  "source": {
    "index": [
      "metrics-kubernetes.container-private.kubernetes.development"
    ],
    "runtime_mappings": {
      "ml_forecast": {
	  	"type": "lookup",
	  	"target_index": ".ml-anomalies-custom-kubernetes_container_resource_regressions_development",
	  	"input_field": "kubernetes.pod.name"
	  	"target_field": "kubernetes.pod.name",
	  	"fetch_fields": ["forecast_*"]
	  }
    }
  },
  "pivot": {
    "group_by": {
      "kubernetes.pod.name": {
        "terms": {
          "field": "kubernetes.pod.name"
        }
      },
      "kubernetes.container.name": {
        "terms": {
          "field": "kubernetes.container.name"
        }
      },
      "ml_forecast": {
        "terms": {
          "field": "ml_forecast"
        }
      }
    },
    "aggregations": {
      "kubernetes.container.cpu.usage.nanocores.avg": {
        "avg": {
          "field": "kubernetes.container.cpu.usage.nanocores"
        }
      }
    }
  },
  "dest": {
    "index": "asdf"
  },
  "sync": {
    "time": {
      "field": "@timestamp"
    }
  }
}

```

This is just a theoretical example, I'm not 100% sure it will work. Just more to demonstrate the idea.

Note, it looks like you can't add lookup runtimes via the Kibana UI, I opened this [issue](https://github.com/elastic/kibana/issues/150914) about it. So, you'll need to create the transform via the Elasticsearch API.

---

_[View the full topic](https://discuss.elastic.co/t/check-forecast-accuracy-with-scripted-field/324650)._
