# Is there a way to get the percentage (%) increase and rate of document growth?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-get-the-percentage-increase-and-rate-of-document-growth/216877>\
**Category:** Kibana\
**Created:** [January 28, 2020, 4:27pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-the-percentage-increase-and-rate-of-document-growth/216877 "2020-01-28T16:27:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norman\_Khine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/norman_khine/32/3342_2.png) [@Norman\_Khine](https://discuss.elastic.co/u/Norman_Khine)\
**Post date:** [January 28, 2020, 4:27pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-the-percentage-increase-and-rate-of-document-growth/216877/1 "2020-01-28T16:27:25Z")

</div>

Hello,  
I have the following code to display the number of document over time in all my indexes:

```auto
.es(q=*, index=analytics-prod*).mvavg(5).lines(width=1.5,stack=true,fill=4).label("analytics-prod").cusum(),
.es(q=*, index=analytics-staging*).mvavg(5).lines(width=1.5,stack=true,fill=4).label("analytics-staging").cusum(),

```

is there a way to get the percentage (%) increase and rate of document growth?

any advice is much appreciated

---

<div class="post-metadata">

**Author:** ![nickofthyme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickofthyme/32/60032_2.png) [@nickofthyme](https://discuss.elastic.co/u/nickofthyme)\
**Post date:** [February 14, 2020, 7:56pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-the-percentage-increase-and-rate-of-document-growth/216877/2 "2020-02-14T19:56:11Z")

</div>

Hey @Norman_Khine, great question!

### Percent Increase

I'm not exactly sure how the percent increase of document count over time would work in timelion. The only thing I could come up with is something like this...

```auto
.es(index=analytics-prod*).mvavg(5).divide(.es(index=analytics-prod*).mvavg(5).cusum()).multiply(100)

```

the difficulty is that it should really be (sum/total cumulative sum) but in timelion the `cusum` only starts accumulating from the starting time range. But to be accurate you need the cumulative sum over the entire history of the index. So this expression will only be accurate when the entire history of the index is within the set time range.

You could correct this if you knew the total historical count, then you could just add that to the `cusum` value, but I don't see a way to get that value.

You may want to look into [Serial Differencing Aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html#search-aggregations-pipeline-serialdiff-aggregation) but I'm not sure if that's what you are looking for.

### Rate of document growth

I think the [`.derivative`](https://github.com/elastic/timelion/blob/master/FUNCTIONS.md#derivative) function may be useful to show the rate of document growth. Something like...

```auto
.es(index=analytics-prod*).mvavg(5).derivative(),

```

Let me know if that helps.

---

<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:** [March 13, 2020, 8:04pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-the-percentage-increase-and-rate-of-document-growth/216877/3 "2020-03-13T20:04:44Z")

</div>

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