# How to split lines based on a term in Timelion using split() or other?

**URL:** <https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851>\
**Category:** Kibana\
**Tags:** timelion\
**Created:** [May 16, 2017, 4:42am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851 "2017-05-16T04:42:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [May 16, 2017, 4:42am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/1 "2017-05-16T04:42:12Z")

</div>

Hi,

I am using ELK GA 5.0.0. In my timelion, I am plotting success error ratio. My log contain time, user, and response. Response can be either `error` or `success`. My current timelion code is;

```
.es(index=mylogs-*, q='response:error',metric=count).divide(.es(index=mylogs-*, q='response:success',metric=count).if("eq", 0, .es(index=mylogs-*, q='response:error',metric=count).multiply(-1))).label("Ratio").lines(show=true,width=2).points(show=true,radius=4,fill=9,weight=0).color(#F00)

```

The code queries for `success` and `error`, and finds the ratio. Also, it handles divion by zero.

I want to split the lines using `username`. That is, the ratio should show for every user. How can I do this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)\
**Post date:** [May 16, 2017, 3:25pm UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/2 "2017-05-16T15:25:12Z")

</div>

Should be able to do this with something like `.es(split=username:X)` where x is the limit of the split.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/e/b/ebb94002b18fdedaf71bee60271079e8680b441d.png)

---

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [May 17, 2017, 4:49am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/3 "2017-05-17T04:49:32Z")

</div>

Hi @Stacey_Gammon ,

Thanks for your reply. Could you tell me where should i place it in my code? I tried;

```
.es(index=mylogs-*, q='response:error',metric=count,split=username:10).divide(.es(index=mylogs-*, q='response:success',metric=count).if("eq", 0, .es(index=mylogs-*, q='response:error',metric=count).multiply(-1))).label("Ratio").lines(show=true,width=2).points(show=true,radius=4,fill=9,weight=0)

```

Is this correct? I have another doubt, I want to display username as labels here. Currently, what I can see is 10 lines and all lines have label `Ratio`. I want to display username there. How can I do this?

---

<div class="post-metadata">

**Author:** ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)\
**Post date:** [May 17, 2017, 11:14am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/4 "2017-05-17T11:14:02Z")

</div>

I think the `.label("ratio")` part is overriding all labels to the string "ratio". What does it look like if you get rid of that?

---

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [May 18, 2017, 4:54am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/5 "2017-05-18T04:54:49Z")

</div>

Hi @Stacey_Gammon , the labels looks like;

```
q:response:error > username.keyword:USER_C > count(84.23)
q:response:error > username.keyword:USER_A > count(35.57)
q:response:error > username.keyword:USER_F > count(20.47)

```

etc

---

<div class="post-metadata">

**Author:** ![Nico-DF](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@Nico-DF](https://discuss.elastic.co/u/Nico-DF)\
**Post date:** [May 18, 2017, 7:05am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/6 "2017-05-18T07:05:39Z")

</div>

You can use Regex in your label.

It will be something like:

```auto
.label(regex='.* username.keyword:(.*) > .*', label='$1')

```

---

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [May 18, 2017, 8:14am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/7 "2017-05-18T08:14:11Z")

</div>

Thanks @Nico-DF , it helped 🙂

---

<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 15, 2017, 8:14am UTC](https://discuss.elastic.co/t/how-to-split-lines-based-on-a-term-in-timelion-using-split-or-other/85851/8 "2017-06-15T08:14:47Z")

</div>

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