# Aggregation and Mapping Types

**URL:** <https://discuss.elastic.co/t/aggregation-and-mapping-types/115989>\
**Category:** Elasticsearch\
**Created:** [January 18, 2018, 8:01am UTC](https://discuss.elastic.co/t/aggregation-and-mapping-types/115989 "2018-01-18T08:01:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sivaprakash\_Shanmuga](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Sivaprakash\_Shanmuga](https://discuss.elastic.co/u/Sivaprakash_Shanmuga)\
**Post date:** [January 18, 2018, 8:01am UTC](https://discuss.elastic.co/t/aggregation-and-mapping-types/115989/1 "2018-01-18T08:01:04Z")

</div>

Hi,

Im storing Device Status data into Elastic to generate reports out of it. Following are list of fields and sample data

DeviceId DeviceType Status Updated\_At

```
10001 50001 ON 2017-12-12 17:04:26
10002 50002 ON 2017-12-12 17:04:34
10001 50001 OFF 2017-12-12 17:08:21
10002 50002 ON 2017-12-12 17:09:27
10001 50001 ON 2017-12-12 17:09:29
10002 50002 OFF 2017-12-12 17:09:43
10001 50001 OFF 2017-12-12 17:09:55
10002 50002 ON 2017-12-12 17:09:58

```

I want to calculate utilization of each device (Group by DeviceId). The way I want to calcualte utilization is calculate number of minutes between ON and OFF of a device. At times I will have consicutive ONs or OFFs as well. Irrespective of that., I want to take ON and next OFF (there coule be multiple ONs before next OFF) then find time difference between them to know how long an utility turned ON. I need to apply Group By on DeviceType to find utilization of group of Devices.

**Clarifications**

- From Mapping perspective., I kept DeviceId and DeviceType as Long, Status as String - Any other better options? Like Keyword as I'll do exact search
- Possible to write a query in ES to achieve what I had mentioned above or I should write the logic in my application?

---

<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:** [February 15, 2018, 8:01am UTC](https://discuss.elastic.co/t/aggregation-and-mapping-types/115989/2 "2018-02-15T08:01:11Z")

</div>

Closed on February 15, 2018, 8:01am UTC

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