Format for multi-level aggregation in Vega


(Steven Ensslen) #1

If I have an ES query that returns JSON like:

 "aggregations": {
  "per_buyer": {
   "doc_count_error_upper_bound": 0,
   "sum_other_doc_count": 0,
   "buckets": [
    {
      "key": "Example-buyer",
      "doc_count": 45,
      "per_cart": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 6,
        "buckets": [
          {
            "key": "397105FB",
            "doc_count": 8,
            "net": {
              "value": 10
            }
          }
        ]
      }
    }
  ]
  }
  }
 },

What is the correct "format" to display data per "per_cart" bucket? Anything deeper than aggregations.per_buyer.buckets returns the error "_.aggregations.per_buyer.buckets.per_cart is undefined" . VEGA_DEBUG.view.data shows that some aggregations.per_buyer.buckets have a per_cart object, which in turn have buckets. Filtering so that all buckets have per_cart objects does not change anything.


Accessing Subbuckets in Vega
How to make a master detail report in Kibana
(kulkarni) #2

@nyuriks - My colleague Yuri can answer this question when he finds time.

Cheers
Rashmi


(system) #3

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


(Yuri Astrakhan) #4

@Steven_Ensslen your format must be aggregations.per_buyer.buckets, simply because that's the list of data that you need. Each data element in that bucket may contain a sub-list of buckets which you have to access from Vega itself. Now, if the sub-list will always have just a single bucket (e.g. if you are summing-up the total per main bucket), you can access it either directly from a mark, e.g. datum.per_cart.buckets[0].net.value, or you can create a formula transform that would copy that value into a top level field, e.g. {type:'formula', as:'net_value', expr: 'datum.per_cart.buckets[0].net.value'}, and use the net_value field in the mark. If on the other hand you have multiple items in the sub-list, you could use the flatten transform to flatten out the sub-buckets into a non-hierarchical list of items, and then use various transformations to get the data into the format you need.