# Timelion: Making expression independent of field values (Use of condition() and first())

**URL:** <https://discuss.elastic.co/t/timelion-making-expression-independent-of-field-values-use-of-condition-and-first/79402>\
**Category:** Kibana\
**Tags:** timelion\
**Created:** [March 21, 2017, 11:46am UTC](https://discuss.elastic.co/t/timelion-making-expression-independent-of-field-values-use-of-condition-and-first/79402 "2017-03-21T11:46:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay\_Joshi](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jay\_Joshi](https://discuss.elastic.co/u/Jay_Joshi)\
**Post date:** [March 21, 2017, 11:46am UTC](https://discuss.elastic.co/t/timelion-making-expression-independent-of-field-values-use-of-condition-and-first/79402/1 "2017-03-21T11:46:58Z")

</div>

Hi,

Fields of my index in which I'm interested in are `method` and `status`, both are of type string.  
`method` can take from dozens of different values.  
`status` can be "success", "pending" or "failure".

I want to plot success rate ( #success/total count) for top 10 methods based on count.  
Expression for success rate for a particular method, say `a` can be as follow:

```
.es(q='method:a AND status:success', method=count).divide(.es(q='method:a'))

```

Using comma separated expressions, I'll have some more method's success rate plotted on the same graph. But, they'll not be for top 10 fields.

The only other way I could think of uses lots of conditionals:

```
.es(q='status:success', split='method:10').if(eq, .es(q='status:success AND method:a'), .es(q='status:success AND method:a').divide(.es(q='method:a'))).if(eq, .es(q='status:success AND method:b'), .es(q='status:success AND method:b').divide(.es(q='method:b'))). ... and so on for all method values.

```

My understanding is, use of first() can shorten the above query, by substituting it as a numerator for divisions in conditionals. But, I guess use of first() in expressions is not allowed. Right? Is there any other alternative to first()?

Is there a way to make this query independent of method values?

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [March 22, 2017, 3:52pm UTC](https://discuss.elastic.co/t/timelion-making-expression-independent-of-field-values-use-of-condition-and-first/79402/2 "2017-03-22T15:52:39Z")

</div>

Are you looking for something like this?

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

And yes, first() is only an internal function.

---

<div class="post-metadata">

**Author:** ![Jay\_Joshi](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jay\_Joshi](https://discuss.elastic.co/u/Jay_Joshi)\
**Post date:** [March 22, 2017, 5:40pm UTC](https://discuss.elastic.co/t/timelion-making-expression-independent-of-field-values-use-of-condition-and-first/79402/3 "2017-03-22T17:40:20Z")

</div>

@Marius_Dragomir Yes. I need a function which can infer which split-series is the input series, and I don't have to write conditionals for every value of a split field.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [March 22, 2017, 5:44pm UTC](https://discuss.elastic.co/t/timelion-making-expression-independent-of-field-values-use-of-condition-and-first/79402/4 "2017-03-22T17:44:43Z")

</div>

For now, a +1 is pretty much what you can do here, the more people that ask for it, the higher up it goes in the priority list.

---

<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:** [April 19, 2017, 5:45pm UTC](https://discuss.elastic.co/t/timelion-making-expression-independent-of-field-values-use-of-condition-and-first/79402/5 "2017-04-19T17:45:23Z")

</div>

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