# How to get a scripted field value as metric in heatmap

**URL:** <https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707>\
**Category:** Kibana\
**Created:** [November 17, 2020, 1:36pm UTC](https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707 "2020-11-17T13:36:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![preeti1211](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@preeti1211](https://discuss.elastic.co/u/preeti1211)\
**Post date:** [November 17, 2020, 1:36pm UTC](https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707/1 "2020-11-17T13:36:23Z")

</div>

```auto
My scenario - 

On heatmap, I want y axis to be defined in three rows, one for each environment(dev,test,val) and x axis should correspond to latest 10 builds for each environment.
Each cell in a heatmap represents a unique build.

Based on the success/failure status of a build for a particular environment, corresponding cell color to be changed to green if succeeded and red if failed.

For that, I have created one scripted field which converts result into an integer value - 1 if succeeded and 0 if failed.
<
if (!doc['result.keyword'].empty) { 
    return doc['result.keyword'].value == "succeeded" ? 1 : 0;    
}   
return null; 
>

But I am not able to figure out how to show colored status of last build for each environment in a heatmap.
Hereby attaching a mock heatmap for your reference.

![heatmap|624x175](upload://nAcCM3jOyKYNFJwMOtAStVNa3Po.jpeg) 

```

Thanks

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [November 18, 2020, 3:57am UTC](https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707/2 "2020-11-18T03:57:32Z")

</div>

Metrics  
min/max of your field value  
Buckets  
x-axis - timestamp per minute/hour/whatever  
y-axis - environment.keyword

This will show the different max/min values of your field, according to the last time span.

---

<div class="post-metadata">

**Author:** ![preeti1211](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@preeti1211](https://discuss.elastic.co/u/preeti1211)\
**Post date:** [November 18, 2020, 12:56pm UTC](https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707/3 "2020-11-18T12:56:35Z")

</div>

Hi AClerk,

```auto
The solution provided by you does not match our requirement.
Let me summarize the usecase in a more precise way.

We want a visualization which should depict the last 10 days build status for each environment(Dev,Test,Val,Prod) where cell color will show status/result of build - succeeded(green) and failed(Red).

Please suggest which visualization should be used for this use case and how can we achieve it.

We have tried using heatmap but it didnot help.

```

Thanks

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [November 19, 2020, 2:51am UTC](https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707/4 "2020-11-19T02:51:48Z")

</div>

Why it does not match the requirments? What are they?  
Can you provide sample data?

---

<div class="post-metadata">

**Author:** ![preeti1211](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@preeti1211](https://discuss.elastic.co/u/preeti1211)\
**Post date:** [November 22, 2020, 12:21pm UTC](https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707/5 "2020-11-22T12:21:20Z")

</div>

Hi,

Now we have changed our approach. we are preparing three different heatmaps for each environment, which resolved our problem

Thanks

---

<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:** [December 20, 2020, 12:21pm UTC](https://discuss.elastic.co/t/how-to-get-a-scripted-field-value-as-metric-in-heatmap/255707/6 "2020-12-20T12:21:22Z")

</div>

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