Possible to create histogram over result of an aggregation?

Hi all,

I think I've been staring at the screen too long because my brain has stopped working! :slight_smile:

Here is the scenario.. I have a mapping with a nested type - here is a snippet of mapping:

    
      "dt" : {"type" : "date"},
          "obs" : { "type" : "nested", "properties" : {"hr" : {"type" : "byte"},"val" : {"type" : "half_float"}}}}

The query I am building (snippet below) does the following:
A terms agg on 'date', to create buckets,
->a nested filter on 'hr'
- ->a (nested) max agg over 'val'.

What I'd like to do is generate a histogram of these results - i.e. something like:

"histogram" : {
                "field" : -> the result of the max agg over 'val'. ,
                "interval" : 0.05
            }

I am guessing it is not possible, as there is no pipeline histogram agg type - but I am hoping someone may have a bright idea?

Many thanks,

Paul

My query:

"dts" : {
            "terms" : { "field" : "date" },
			"aggs" : {
				"obs" : {
					"nested" : {
						"path" : "obs"
					},
					"aggs" : {  
						"hours" : {
							"filter" : { "terms" : { "obs.hr" : ["11", "12", "13", "14"]} },
							"aggs" : {
							"thresholds" : {"max" : { "field" : "obs.val" } }
							}
						}
					}
				}
			}
		}

The result (abbreviated).

{
          "key_as_string" : "2014-12-24T00:00:00.000Z",
          "obs" : {
            "hours" : {
              "thresholds" : {
                "val" : 0.01000213623046875
              }
            }
          }
        }

Yeah, I'm afraid you're right: that'd be in the purview of pipeline aggs (aggregating the result of other aggregations) and we don't have anything of the sort available atm. It'd be nice to have though! Filing onto my to-investigate list :slight_smile:

I think you'll basically have to take the results of the agg response and construct the histogram yourself, client-side. Sorry :disappointed:

Thanks Zachary - I thought as much... Luckily there is an absolute worst-case upper bound (in my app) of around 6k results for the MAX aggregation in question; I'm building the histogram manually which is not too painful a hit :slight_smile:

It may be that my app has odd requirements; it's doing weather analytics with some pretty flexible ways of slicing up time. But for me at least I think a pipelinable histogram would be uber-useful in a bunch of scenarios...

Thanks for taking the time to respond, greatly appreciated - and keep up the awesome work on Elastic! Aggs ftw! lol :wink:

Happy to help! Once I dig myself out from a couple of projects, there are several pipeline aggs I'd like to work on. I'll keep this one in mind if/when that time comes :slight_smile:

Weather analytics sounds cool! Anywhere to read more about what you're doing? You've got me curious!

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