# Summing up maximum values per device per specific time

**URL:** https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700
**Category:** Elasticsearch
**Created:** [December 7, 2017, 3:03pm UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700 "2017-12-07T15:03:17Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![emil.mirzayev](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@emil.mirzayev](https://discuss.elastic.co/u/emil.mirzayev)
#### Post date: [December 7, 2017, 3:03pm UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/1 "2017-12-07T15:03:18Z")

</div>

Hi! I have data with timestamp, device\_id and value. I have around 1k devices which signal me their values. Value in **t** is always smaller or equal to the value in **t+1**. Which means, values are gradually increasing (in t if it was 1500, in t+1 it is 1503 and etc.). What I want to do, is to write a script which sums up maximum values per device\_id per given time frame and then visualize it in timelion. How is this possible? My data structure is:  
timestamp, device\_id, ..(some not useful fields for this question).., value;  
timestamp, another\_device\_id, .... , value;  
timestamp+t, device\_id, .... , value;  
timestamp + t, another\_device\_id, .... , value;

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [December 15, 2017, 9:17am UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/2 "2017-12-15T09:17:06Z")

</div>

> [@emil.mirzayev](#):
>
> I have around 1k devices

> [@emil.mirzayev](#):
>
> maximum values per device\_id per given time frame

Just wanting to size this query - are you saying you want 1000 data points for a single timeframe e.g "last week" or that you want multiple timeframes e.g. minute-level data points for the last 24 hours (=1000 x 24 x 60)

---

<div class="post-metadata">

### Author: ![emil.mirzayev](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@emil.mirzayev](https://discuss.elastic.co/u/emil.mirzayev)
#### Post date: [December 19, 2017, 8:07am UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/3 "2017-12-19T08:07:19Z")

</div>

I want to sum up all data points (maximum consumptions of all devices) within the given frame. The thing is, I am interested in the latest value (which will be the maximum value) of each device summed up. For now, i have 1k devices, but they will probably increase in number soon. is it a way to do it dynamically? So that when i have 100k devices i don't have to re-edit the code again?

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [December 19, 2017, 8:36am UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/4 "2017-12-19T08:36:51Z")

</div>

I still need the answer to the question about number of timeframes in the response. It determines whether this can be a single request.

---

<div class="post-metadata">

### Author: ![emil.mirzayev](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@emil.mirzayev](https://discuss.elastic.co/u/emil.mirzayev)
#### Post date: [December 19, 2017, 8:51am UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/5 "2017-12-19T08:51:09Z")

</div>

Sorry for my misunderstanding. My time frame can be e.g last month, last 6 months, one year

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [December 19, 2017, 8:56am UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/6 "2017-12-19T08:56:16Z")

</div>

That's the time range but I also need to know how many units that's divided into.  
Perhaps put another way - how many lines of JSON do you think you'll need in a response?

---

<div class="post-metadata">

### Author: ![emil.mirzayev](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@emil.mirzayev](https://discuss.elastic.co/u/emil.mirzayev)
#### Post date: [December 19, 2017, 9:05am UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/7 "2017-12-19T09:05:54Z")

</div>

One line per every timestamp. In other words, grouping by devices and timestamp and summing up maximum values, so that, for every timestamp field i will have the sum of all max values of all devices

---

<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: [January 16, 2018, 9:06am UTC](https://discuss.elastic.co/t/summing-up-maximum-values-per-device-per-specific-time/110700/8 "2018-01-16T09:06:00Z")

</div>

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