# Consumption calculation

**URL:** <https://discuss.elastic.co/t/consumption-calculation/79682>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 4:26am UTC](https://discuss.elastic.co/t/consumption-calculation/79682 "2017-03-23T04:26:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![karnamonkster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnamonkster/32/67266_2.png) [@karnamonkster](https://discuss.elastic.co/u/karnamonkster)\
**Post date:** [March 23, 2017, 4:26am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/1 "2017-03-23T04:26:55Z")

</div>

Hi,  
I am running a test environment with following:  
ES & Kibana:5.2.2

- I imported 2 .csv files from different paths using logstash input

- I have created one index "meters" for both csv files.

- These contain metering statistics

- I have a field named "path"- which gives me the name of csv file such as:

- path: "drive:/some/path/data\_as\_on\_2017-03-15"

- path: "drive:/some/path/data\_as\_on\_2017-03-16"

- Another field named "meter\_read"(number) provides me the reading of meters for all metering station for specific dates.

- Now i need to plot a line or bar chart for the meter\_read difference calculated from different .csv which will be like consumption on 2017-03-15

- consumption on 2017-03-16

- And the difference between the meter\_read value for these 2 dates.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 23, 2017, 6:02am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/2 "2017-03-23T06:02:23Z")

</div>

I'd try with Timelion to plot the 2 lines, shift one line with a 1 day offset then ask Timelion to do a difference.

---

<div class="post-metadata">

**Author:** ![karnamonkster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnamonkster/32/67266_2.png) [@karnamonkster](https://discuss.elastic.co/u/karnamonkster)\
**Post date:** [March 23, 2017, 10:28am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/3 "2017-03-23T10:28:07Z")

</div>

How does it work in case i have static data with no time stamp

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 23, 2017, 10:42am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/4 "2017-03-23T10:42:51Z")

</div>

You can't then. But I thought you were mentioning time based data as you wanted to compare by 2 dates.

---

<div class="post-metadata">

**Author:** ![karnamonkster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnamonkster/32/67266_2.png) [@karnamonkster](https://discuss.elastic.co/u/karnamonkster)\
**Post date:** [March 26, 2017, 4:01am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/5 "2017-03-26T04:01:08Z")

</div>

Ok, then is there anyway i can add a new field which stores the difference such as  
meter\_read\_csv1 - meter\_read\_csv2  
which may be plotted on the graph showing the consumption.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2017, 7:10am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/6 "2017-03-26T07:10:54Z")

</div>

Within the same document?

Yes you can compute that on client side or use a script on elasticsearch side (update API or ingest API).

---

<div class="post-metadata">

**Author:** ![karnamonkster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnamonkster/32/67266_2.png) [@karnamonkster](https://discuss.elastic.co/u/karnamonkster)\
**Post date:** [March 26, 2017, 8:17am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/7 "2017-03-26T08:17:54Z")

</div>

Thanks David,  
I am new to ES and scripted fields, so are there any pointers or example I  
may refer with the same query.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2017, 10:24am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/8 "2017-03-26T10:24:13Z")

</div>

- [https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html#\_scripted\_updates](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html#_scripted_updates)
- [https://www.elastic.co/guide/en/elasticsearch/reference/5.2/script-processor.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/script-processor.html)

---

<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 23, 2017, 10:24am UTC](https://discuss.elastic.co/t/consumption-calculation/79682/9 "2017-04-23T10:24:13Z")

</div>

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