# How to show the metrics of adding two fields through Timelion visualization

**URL:** https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985
**Category:** Kibana
**Tags:** timelion
**Created:** [June 29, 2018, 2:30pm UTC](https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985 "2018-06-29T14:30:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hyzhang6639](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hyzhang6639/32/32515_2.png) [@hyzhang6639](https://discuss.elastic.co/u/hyzhang6639)
#### Post date: [June 29, 2018, 2:30pm UTC](https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985/1 "2018-06-29T14:30:44Z")

</div>

There are two fields such as field1, field2. I need to show the time series data of adding two fields. I tried the below scripts in Timelion visualization and it can't work.

.es(index=index\_t, metric='field1+field2').label('NewLabel').color(#1E90FF)

Whether some methods can resolve the issue?

---

<div class="post-metadata">

### Author: ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)
#### Post date: [June 29, 2018, 3:50pm UTC](https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985/2 "2018-06-29T15:50:00Z")

</div>

hi @hyzhang6639,

I guess there's two answers, depending on what to sum:

* * *

to sum two series, you need to use the `.sum()` function from Timelion. See [https://github.com/elastic/timelion/blob/master/FUNCTIONS.md#sum](https://github.com/elastic/timelion/blob/master/FUNCTIONS.md#sum).

it'd be something like

`.es(index=index_t,metric='avg:field1').sum(.es(index=index_t,metric='avg:field2')).label('foobar').color(#190FF)`

* * *

If summing series is not what you want, you may want to use a scripted-field instead. This will allow you to create a script that sums the two fields. See [https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html) for details.

e.g. suppose we create this scripted field

`doc['field'].value +doc['field2'].value`

and call it `sum_field`

You can then use it in your timelion expression

`.es(index=index_t, metric='sum_field').label('NewLabel').color(#1E90FF)`

---

<div class="post-metadata">

### Author: ![hyzhang6639](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hyzhang6639/32/32515_2.png) [@hyzhang6639](https://discuss.elastic.co/u/hyzhang6639)
#### Post date: [June 30, 2018, 1:24am UTC](https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985/3 "2018-06-30T01:24:58Z")

</div>

> [@thomasneirynck](#):
>
> doc['field'].value +doc['field2'].value

Hi @thomasneirynck  
Thanks for your response. The scripted field can satisfy my requirement. But it appears that scripted\_filed only can be used in Timelion visualization. I can't find the new created scripted fields in other visualization in Kibana. It appears that it can't be referenced in other visualization. May I need additional configuration to use the scripted fields in other visualization?

---

<div class="post-metadata">

### Author: ![hyzhang6639](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hyzhang6639/32/32515_2.png) [@hyzhang6639](https://discuss.elastic.co/u/hyzhang6639)
#### Post date: [July 2, 2018, 6:51am UTC](https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985/4 "2018-07-02T06:51:42Z")

</div>

Hi @thomasneirynck  
Thanks for your updates. For examples, I created a new script fields RESPTIME in ES, but I can't see the new script field RESPTIME in the field dropdown list of "Visual Builder" visualization in Kibana. Whether I need some additional configuration to reference this new field in the dropdown list of "Visual Builder" or other visualizations?

Best Regards  
Hongyi

---

<div class="post-metadata">

### Author: ![hyzhang6639](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hyzhang6639/32/32515_2.png) [@hyzhang6639](https://discuss.elastic.co/u/hyzhang6639)
#### Post date: [July 2, 2018, 7:02am UTC](https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985/5 "2018-07-02T07:02:26Z")

</div>

Hi @thomasneirynck

I see the similar issue on the below link:

> <https://github.com/elastic/kibana/issues/11999>

I'm wondering which release can fix this issue?

---

<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 30, 2018, 7:02am UTC](https://discuss.elastic.co/t/how-to-show-the-metrics-of-adding-two-fields-through-timelion-visualization/137985/6 "2018-07-30T07:02:34Z")

</div>

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