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

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?

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.

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 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)

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?

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

Hi @thomasneirynck

I see the similar issue on the below link:

I'm wondering which release can fix this issue?

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