# 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:** 1\
**Showing post:** 2

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

---

_[View the full topic](https://discuss.elastic.co/t/timelion-how-generate-label-dynamically/85072)._
