# Performing range summary on the result of a metric within a bucket

**URL:** https://discuss.elastic.co/t/performing-range-summary-on-the-result-of-a-metric-within-a-bucket/15530
**Category:** Elasticsearch
**Created:** [January 31, 2014, 3:42pm UTC](https://discuss.elastic.co/t/performing-range-summary-on-the-result-of-a-metric-within-a-bucket/15530 "2014-01-31T15:42:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)
#### Post date: [January 31, 2014, 3:42pm UTC](https://discuss.elastic.co/t/performing-range-summary-on-the-result-of-a-metric-within-a-bucket/15530/1 "2014-01-31T15:42:45Z")

</div>

I have what will be a long running time series table that I would like to  
aggregate by time buckets and analyze:

1. Query & Filter (in this case by dates & a term query on user\_guid)  
(Working)
2. Bucket by time for analysis (working using the aggs "date\_aggregate"  
and "heartRate\_stats" aggs
3. Perform range counts on the metrics produced by the metrics within  
the buckets. \*Not working. \*The "heartRate\_zoneCounts1" aggregator gets  
zero counts - seems you can't point from the top down. The  
"heartRate\_zoneCounts" aggregator does counts of the individual documents  
within the bucket (nice - but not what I'm looking for).

So how would I apply a range aggregate to the outcome of the  
heartRate\_stats metric and get only one value per date\_aggregate bucket? I  
can post process the results to apply a range but would rather have ES do  
it for me. Any / all help apprecuated. Thanks in advance!  
--Mike

_The Results_  
mikeasick [https://gist.github.com/mikeasick](https://gist.github.com/mikeasick) /  
_gist:8734325_[https://gist.github.com/mikeasick/8734325](https://gist.github.com/mikeasick/8734325)

_The Data (per second stream of the information below)_  
mikeasick [https://gist.github.com/mikeasick](https://gist.github.com/mikeasick) / _gist:8734404  
 [https://gist.github.com/mikeasick/8734404](https://gist.github.com/mikeasick/8734404)_

_The Search_

> <https://gist.github.com/mikeasick/8734117>

curl -XGET "[http://localhost:9200/vitals/vital/\_search?pretty=true](http://localhost:9200/vitals/vital/_search?pretty=true)" -d'  
{

"size": 0,  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {

```
    "and": {
      "filters": [
        {
          "term": {"user_guid": "0ad08904-c1cf-46cf-9a04-e0865c1cced2"}
        },
        {
          "numeric_range": {

            "recorded_time": {
              "gte": "2013-01-05T04:44:33.396-05:00",
              "lte": "2014-01-05T04:44:33.396-05:00"
            }
          }
        }

      ]
    }
  }
}

```

},  
"aggs": {  
"date\_aggregate": {  
"date\_histogram": {  
"field": "recorded\_time",  
"interval": "5m"

```
  },
  "aggs": {
    "heartRate_zoneAverageCounts": {

       "range" : {
            "field" : "heartRate_stats.avg",
            "ranges" : [
                { "to" : 50 },
                { "from" : 50, "to" : 100 },

                { "from" : 100 }
            ]
        }

    },
    "heartRate_zoneCounts": {
       "range" : {

            "field" : "heartRate",
            "ranges" : [
                { "to" : 50 },
                { "from" : 50, "to" : 100 },
                { "from" : 100 }

            ]
        }
    },
    "heartRate_stats": {
      "extended_stats": {
        "field": "heartRate"

      }
    }
  }
}

```

}  
}'

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAP8axnB\_ysa7DMMnsxou%2BJoaPe7kzT3CooLrn\_oYi1petadF8A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAP8axnB_ysa7DMMnsxou%2BJoaPe7kzT3CooLrn_oYi1petadF8A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)
#### Post date: [January 31, 2014, 5:58pm UTC](https://discuss.elastic.co/t/performing-range-summary-on-the-result-of-a-metric-within-a-bucket/15530/2 "2014-01-31T17:58:33Z")

</div>

Forgot to post the mapping (here mikeasick[https://gist.github.com/mikeasick](https://gist.github.com/mikeasick) /  
gist:8738689 [https://gist.github.com/mikeasick/8738689](https://gist.github.com/mikeasick/8738689)) and that it's  
using 1.0.0.Beta2 and Java 1.7.0\_25 on Windows 7.

Thanks!

On Fri, Jan 31, 2014 at 10:42 AM, Michael Sick \<  
[michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:

> I have what will be a long running time series table that I would like to  
> aggregate by time buckets and analyze:
> 
> 1. Query & Filter (in this case by dates & a term query on user\_guid)  
> (Working)
> 2. Bucket by time for analysis (working using the aggs  
> "date\_aggregate" and "heartRate\_stats" aggs
> 3. Perform range counts on the metrics produced by the metrics within  
> the buckets. \*Not working. \*The "heartRate\_zoneCounts1" aggregator  
> gets zero counts - seems you can't point from the top down. The  
> "heartRate\_zoneCounts" aggregator does counts of the individual documents  
> within the bucket (nice - but not what I'm looking for).
> 
> So how would I apply a range aggregate to the outcome of the  
> heartRate\_stats metric and get only one value per date\_aggregate bucket? I  
> can post process the results to apply a range but would rather have ES do  
> it for me. Any / all help apprecuated. Thanks in advance!  
> --Mike
> 
> _The Results_  
> mikeasick [https://gist.github.com/mikeasick](https://gist.github.com/mikeasick) / _gist:8734325_[https://gist.github.com/mikeasick/8734325](https://gist.github.com/mikeasick/8734325)
> 
> _The Data (per second stream of the information below)_  
> mikeasick [https://gist.github.com/mikeasick](https://gist.github.com/mikeasick) / _gist:8734404  
> [https://gist.github.com/mikeasick/8734404](https://gist.github.com/mikeasick/8734404)_
> 
> _The Search_  
> [ES Aggregates: Metrics on Metrics Example Query · GitHub](https://gist.github.com/mikeasick/8734117)
> 
> curl -XGET "[http://localhost:9200/vitals/vital/\_search?pretty=true](http://localhost:9200/vitals/vital/_search?pretty=true)" -d'  
> {
> 
> "size": 0,  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {
> 
> ```
> "and": {
> "filters": [
> {
> "term": {"user_guid": "0ad08904-c1cf-46cf-9a04-e0865c1cced2"}
> },
> {
> "numeric_range": {
> 
> "recorded_time": {
> "gte": "2013-01-05T04:44:33.396-05:00",
> "lte": "2014-01-05T04:44:33.396-05:00"
> 
> }
> }
> }
> 
> ]
> }
> }
> }
> 
> ```
> 
> },  
> "aggs": {  
> "date\_aggregate": {  
> "date\_histogram": {  
> "field": "recorded\_time",  
> "interval": "5m"
> 
> ```
> },
> "aggs": {
> "heartRate_zoneAverageCounts": {
> 
> "range" : {
> "field" : "heartRate_stats.avg",
> "ranges" : [
> { "to" : 50 },
> { "from" : 50, "to" : 100 },
> 
> { "from" : 100 }
> ]
> }
> 
> },
> "heartRate_zoneCounts": {
> "range" : {
> 
> "field" : "heartRate",
> "ranges" : [
> { "to" : 50 },
> { "from" : 50, "to" : 100 },
> { "from" : 100 }
> 
> ]
> }
> },
> "heartRate_stats": {
> "extended_stats": {
> "field": "heartRate"
> 
> }
> }
> }
> }
> 
> ```
> 
> }  
> }'

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAP8axnC1gLEhXk02jKUeP2MQSSeFemmGczvbPTa2eERwqMtYkg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAP8axnC1gLEhXk02jKUeP2MQSSeFemmGczvbPTa2eERwqMtYkg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 6, 2017, 1:53am UTC](https://discuss.elastic.co/t/performing-range-summary-on-the-result-of-a-metric-within-a-bucket/15530/3 "2017-07-06T01:53:36Z")

</div>


