# How to use timelion to get a ratio

**URL:** https://discuss.elastic.co/t/how-to-use-timelion-to-get-a-ratio/105457
**Category:** Kibana
**Tags:** timelion
**Created:** [October 26, 2017, 4:51pm UTC](https://discuss.elastic.co/t/how-to-use-timelion-to-get-a-ratio/105457 "2017-10-26T16:51:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ximeng\_Zhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ximeng_zhao/32/15775_2.png) [@Ximeng\_Zhao](https://discuss.elastic.co/u/Ximeng_Zhao)
#### Post date: [October 26, 2017, 4:51pm UTC](https://discuss.elastic.co/t/how-to-use-timelion-to-get-a-ratio/105457/1 "2017-10-26T16:51:35Z")

</div>

Hello,

I want to write a script in Timelion to get a ratio.  
The idea is :  
count(field\_name) is not null divided by count(field\_name)

1. The index name: call
2. The field name I want to count : drop\_rate
3. The value of drop\_rate are 1,2,5,NULL.

My script:  
.es(index='call',timefield=ts, q='_exists_:drop\_rate').divide(.es(index='call',timefield=ts)).multiply(100)

It can run, but I think the result is not correct, I think I made something wrong in the query part, please help me, thanks.

John

---

<div class="post-metadata">

### Author: ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)
#### Post date: [October 27, 2017, 3:20am UTC](https://discuss.elastic.co/t/how-to-use-timelion-to-get-a-ratio/105457/2 "2017-10-27T03:20:27Z")

</div>

I believe it should be `_exists_:drop_rate`

---

<div class="post-metadata">

### Author: ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)
#### Post date: [October 27, 2017, 3:31am UTC](https://discuss.elastic.co/t/how-to-use-timelion-to-get-a-ratio/105457/3 "2017-10-27T03:31:31Z")

</div>

Actually, upon further investigation, it doesn't appear that worked.

I will come back to this tomorrow.

Here is my sample data:

```auto
DELETE /discuss-105457

PUT /discuss-105457
{
  "mappings": {
    "doc": {
      "properties": {
        "drop_rate": {
          "type": "integer"
        },
        "@timestamp": {
          "type": "date"
        }
      }
    }
  }
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T01:00:00+00:00",
  "drop_rate": null
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T01:00:00+00:00",
  "drop_rate": null
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T02:00:00+00:00",
  "drop_rate": 1
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T03:00:00+00:00",
  "drop_rate": 1
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T03:00:00+00:00",
  "drop_rate": null
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T03:00:00+00:00",
  "drop_rate": null
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T04:00:00+00:00",
  "drop_rate": 2
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T04:00:00+00:00",
  "drop_rate": null
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T05:00:00+00:00",
  "drop_rate": 1
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T06:00:00+00:00",
  "drop_rate": 5
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T07:00:00+00:00",
  "drop_rate": 1
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T08:00:00+00:00",
  "drop_rate": 2
}

POST /discuss-105457/doc
{
  "@timestamp": "2017-10-26T09:00:00+00:00",
  "drop_rate": 1
}

```

```auto
.es(index='discuss-105457', timefield=@timestamp).label('all').lines(fill=1,width=0.5).color(gray), .es(index='discuss-105457', timefield=@timestamp, q='_exists_:drop_rate').label('dropped')

```

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

---

<div class="post-metadata">

### Author: ![Ximeng\_Zhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ximeng_zhao/32/15775_2.png) [@Ximeng\_Zhao](https://discuss.elastic.co/u/Ximeng_Zhao)
#### Post date: [October 27, 2017, 3:10pm UTC](https://discuss.elastic.co/t/how-to-use-timelion-to-get-a-ratio/105457/4 "2017-10-27T15:10:52Z")

</div>

@tylersmalley Thanks, I figure it out, here is my script.

(.es(index='call',timefield=ts, q='_exists_:drop\_rate).divide(.es(index='call',timefield=ts))).multiply(100).yaxis(label="Drop Percentage").lines(width=3, fill=3, steps=T).color(green)

---

<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: [November 24, 2017, 3:10pm UTC](https://discuss.elastic.co/t/how-to-use-timelion-to-get-a-ratio/105457/5 "2017-11-24T15:10:53Z")

</div>

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