# Timelion: how generate .label() dynamically?

**URL:** <https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072>\
**Category:** Kibana\
**Created:** [May 9, 2017, 11:16am UTC](https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072 "2017-05-09T11:16:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [May 9, 2017, 11:16am UTC](https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072/1 "2017-05-09T11:16:34Z")

</div>

Hi,

I am using split function in timelion to do a term aggregation and to produce mutliple lines by grouping.  
The query is quite long and I want to set a custom label, which includes fields of the query.

Example:  
I split for the filed type.

That gives me 3 lines, one for (type1, type2, type3)  
Now I want to set a custom lable, which should be as following:

`"my very own static text" [type]`

So this should result into:  
my very own static text type1  
my very own static text type2  
my very own static text type3

How can I do that?

Thanks, Andreas

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [May 9, 2017, 12:37pm UTC](https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072/2 "2017-05-09T12:37:07Z")

</div>

Hi @asp,

when you look at the series labels that Timelion generates by default for a query like `.es(q="*", metric="avg:bytes", split="type:10")`, it probably looks something like this:

```
q:* > type:type1 > avg(bytes)

```

with the `*` being the query supplied to `.es()`, `type:type1` being the type this time series corresponds to and `avg(bytes)` being the aggregation in the `metric` argument of `.es()`. To transform this label into something like you requested you can use the `.label()` function with its regex functionality, e.g.:

```
.es(metric="avg:bytes", split="type:10").label("my very own static text [$1]", "^.* > type:(\S+) > .*")

```

That should produce `my very own static text [type1]` as the label for the series corresponding to `type1`. It replaces every occurence of the regular expression given as the second argument to `.label()` with the first argument, substituting first capture group `(\S+)` for the `$1` back-reference. See the [MDN Regexp documentation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp) for an explanation of the various other special characters.

---

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [May 9, 2017, 12:46pm UTC](https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072/3 "2017-05-09T12:46:24Z")

</div>

cool, works perfectly. thanks. Didn't found an example for the regex functionality before.

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [May 9, 2017, 1:00pm UTC](https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072/4 "2017-05-09T13:00:00Z")

</div>

It is only mentioned very briefly in the in-app docs:

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

I agree that the [guide](https://www.elastic.co/guide/en/kibana/current/timelion-customize.html) could explain that better.

---

<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:** [June 6, 2017, 1:00pm UTC](https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072/5 "2017-06-06T13:00:49Z")

</div>

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