# Plot results of a script aggregation

**URL:** https://discuss.elastic.co/t/plot-results-of-a-script-aggregation/152057
**Category:** Kibana
**Created:** [October 11, 2018, 1:25pm UTC](https://discuss.elastic.co/t/plot-results-of-a-script-aggregation/152057 "2018-10-11T13:25:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![parosio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parosio/32/27367_2.png) [@parosio](https://discuss.elastic.co/u/parosio)
#### Post date: [October 11, 2018, 1:25pm UTC](https://discuss.elastic.co/t/plot-results-of-a-script-aggregation/152057/1 "2018-10-11T13:25:08Z")

</div>

Hello, I'm trying to plot the results of a custom scripted aggregation, such as the following (based on flight data from [https://demo.elastic.co](https://demo.elastic.co))

The aggregation returns the number of flights with the same weather in Origin and Destination:

```
GET flights/_search
{
  "size": 0,
  "_source": {
    "excludes": []
  },
  "aggs": {
    "whatever": {
      "composite": {
        "sources": [
          {
            "2": {
              "terms": {
                "script": {
                  "source": "if (doc['DestWeather.keyword'] == doc['OriginWeather.keyword']) return doc['DestWeather.keyword']; ",
                  "lang": "painless"
                }
              }
            }
          }
        ]
      }
    }
  },
  "query": {
    "match_all": {}
  }
}

```

and has been suggested in [this](https://discuss.elastic.co/t/searching-for-matching-fields/148572) elastic thread.

Another way to put it: only show the diagonal of this Heatmap:

 ![sameWeather](https://us1.discourse-cdn.com/elastic/original/3X/4/6/460eeb7588cbf2541fa3ccec323d3121eeef2f0d.png)

I tried to use the above script in the 'JSON input' field of DestWeather aggregation, but only raised a variety of errors.

Am I correct [this](https://github.com/elastic/kibana/issues/2646) is the correct kibana thread to follow, or the question already has a solution?

---

<div class="post-metadata">

### Author: ![jen-huang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jen-huang/32/74327_2.png) [@jen-huang](https://discuss.elastic.co/u/jen-huang)
#### Post date: [October 11, 2018, 2:34pm UTC](https://discuss.elastic.co/t/plot-results-of-a-script-aggregation/152057/2 "2018-10-11T14:34:41Z")

</div>

Try adding this script as a scripted field in **Management \> Index Patterns \> Add scripted field**. Then, you will be able to use the new field in the heat map visualization.

---

<div class="post-metadata">

### Author: ![parosio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parosio/32/27367_2.png) [@parosio](https://discuss.elastic.co/u/parosio)
#### Post date: [October 12, 2018, 1:19pm UTC](https://discuss.elastic.co/t/plot-results-of-a-script-aggregation/152057/3 "2018-10-12T13:19:21Z")

</div>

Thank you, could not actually test it on flight example, but it should work.

---

<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 9, 2018, 1:23pm UTC](https://discuss.elastic.co/t/plot-results-of-a-script-aggregation/152057/4 "2018-11-09T13:23:59Z")

</div>

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