How variable width histogram with nested aggregations works

Hi,
I want to use the variable_width_histogram combined with other aggregations, such as min or max

Here is an example of combinated aggregations on a numeric field:

"aggs": {
        "aggregated-items": {
            "variable_width_histogram": {
                "buckets": 5,
                "field": "freespace"
            },
            "aggs": {
                "max-aggs": {
                    "max": {
                        "field": "freespace"
                    }
                }
            }
        }
    }

Here is the result I got:

 "aggregations": {
        "aggregated-items": {
          "buckets": [
                {
                    "min": 100.0,
                    "key": 111.67054263565892,
                    "max": 124.0,
                    "doc_count": 258,
                    "max-aggs": {
                        "value": 200.0
                    }
                },
                {
                    "min": 124.0,
                    "key": 134.45454545454547,
                    "max": 145.0,
                    "doc_count": 198,
                    "max-aggs": {
                        "value": 200.0
                    }
                },
                {
                    "min": 145.0,
                    "key": 157.73333333333332,
                    "max": 171.0,
                    "doc_count": 270,
                    "max-aggs": {
                        "value": 200.0
                    }
                },
                {
                    "min": 172.0,
                    "key": 180.82323232323233,
                    "max": 191.0,
                    "doc_count": 198,
                    "max-aggs": {
                        "value": 200.0
                    }
                },
                {
                    "min": 192.0,
                    "key": 196.11764705882354,
                    "max": 200.0,
                    "doc_count": 85,
                    "max-aggs": {
                        "value": 198.0
                    }
                }
            ]
        }
    }

I don't understant why the max-aggs value is 200.0 in first buckets and why it's 198.0 in the last bucket. I would expect the max-aggs to be the same as the max of the corresponding bucket, ie 124.0 in the first, etc.

So, I would like to know how this max-aggs value is calulcated when used under a variable_width_histogram ?

Thanks !

Hi,

Does "freespace" field have multiple values in array?
As bucket aggregation works for bucketing documents, each variable_width_histogram bucket may contain documents with a value of "freespace" between the range. If the documents have other values for "freespace" field, the sub-aggregation uses all the values for aggregation.

If you have to aggregate such values separately, storing them in individual nested objects may be an solution.

Hi,

Thanks for your answer, now I understand better how it works when aggregating arrays. Infortunately, the "freespace" fields is not an array.

However, it works perfectly when I use an histogram. So I don't know why I don't have same max with variable_width_histogram.

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