# Kibana vega viz plug-in:multiple aggregations: how-to?

**URL:** https://discuss.elastic.co/t/kibana-vega-viz-plug-in-multiple-aggregations-how-to/121893
**Category:** Kibana
**Created:** [February 28, 2018, 4:36pm UTC](https://discuss.elastic.co/t/kibana-vega-viz-plug-in-multiple-aggregations-how-to/121893 "2018-02-28T16:36:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![nielsen-at-cgt](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nielsen-at-cgt](https://discuss.elastic.co/u/nielsen-at-cgt)
#### Post date: [February 28, 2018, 4:36pm UTC](https://discuss.elastic.co/t/kibana-vega-viz-plug-in-multiple-aggregations-how-to/121893/1 "2018-02-28T16:36:08Z")

</div>

The vega viz plugin for kibana is really good!

I'm having a slight problem though, and I fear I might be going past the capability of the plugin.

What I would like to produce is a graphic with multiple rows, one for each "site", with each row comprising dates on the X-axis with the document count for each site/date displayed as a bar.

What I get with the following is a blank screen.

Can this be done?

Here's my specification:

```
 {
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "title": "Event counts from all indexes",
  "data": {
    "url": {
      "index": "prd-vizql-*",
      "body": {
        "aggs": {
          "site": {
            "aggs": {
              "date": {
                "aggs": {
                  "sessions": {
                    "terms": {
                      "size": 500,
                      "field": "json.v.sess.keyword"
                    }
                  }
                },
                "date_histogram": {
                  "field": "@timestamp",
                  "interval": "day",
                  "min_doc_count": 0
                }
              }
            },
            "terms": {
              "size": 500,
              "field": "json.v.site.keyword"
            }
          }
        },
        "size": 0,
        "query": {
          "bool": {
            "filter": [
              {"exists": {"field": "json.v.workbook"}},
              {"terms": {"json.k.keyword": ["create-session"]}}
            ]
          }
        }
      }
    },
    "format": {"property": "aggregations.site.buckets"}
  },
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "date.buckets.key",
      "type": "temporal",
      "axis": {"title": false, "grid": false}
    },
    "y": {
      "field": "date.buckets.doc_count",
      "type": "quantitative",
      "axis": {"title": "Document count"}
    },
    "row": {"field": "key", "type": "nominal", "header": "Site"}
  }
}

```

and here's a sample of my data:

```
 "aggregations": {
    "site": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "XYZ Company",
          "doc_count": 324,
          "date": {
            "buckets": [
              {
                "key_as_string": "2018-01-16T00:00:00.000Z",
                "key": 1516060800000,
                "doc_count": 36,
                "sessions": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "key": "0513156BCA584D4D8AAB5ACDD18B175D-0:0",
                      "doc_count": 1
                    },
                    {
                      "key": "062B082F67534A0BBA7CD3A939AFE32F-0:2",
                      "doc_count": 1
                    },
                    {
                      "key": "067189C42986479D86E59BB2D14B349B-0:2",
                      "doc_count": 1
                    },
                    {
                      "key": "0A31D32462604F0D88BDF495FA8327DD-0:0",
                      "doc_count": 1
                    },
```

---

<div class="post-metadata">

### Author: ![nyuriks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nyuriks/32/26171_2.png) [@nyuriks](https://discuss.elastic.co/u/nyuriks)
#### Post date: [March 2, 2018, 1:10am UTC](https://discuss.elastic.co/t/kibana-vega-viz-plug-in-multiple-aggregations-how-to/121893/2 "2018-03-02T01:10:15Z")

</div>

@nielsen-at-cgt Vega-Lite does not have a good built-in handling of nested data results, so I would advise you use [composite aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html).  
See an example in the video linked from the recent [Vega blog post](https://www.elastic.co/blog/custom-vega-visualizations-in-kibana).

If you need to process nested data, you can use full Vega language instead - the ["group" mark](https://vega.github.io/vega/docs/marks/) can be used to draw pre-faceted data.

---

<div class="post-metadata">

### Author: ![nielsen-at-cgt](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nielsen-at-cgt](https://discuss.elastic.co/u/nielsen-at-cgt)
#### Post date: [March 2, 2018, 2:14am UTC](https://discuss.elastic.co/t/kibana-vega-viz-plug-in-multiple-aggregations-how-to/121893/3 "2018-03-02T02:14:02Z")

</div>

Thanks Yuri, I will look into that.

---

<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: [March 30, 2018, 2:14am UTC](https://discuss.elastic.co/t/kibana-vega-viz-plug-in-multiple-aggregations-how-to/121893/4 "2018-03-30T02:14:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nyuriks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nyuriks/32/26171_2.png) [@nyuriks](https://discuss.elastic.co/u/nyuriks)
#### Post date: [March 30, 2018, 7:38pm UTC](https://discuss.elastic.co/t/kibana-vega-viz-plug-in-multiple-aggregations-how-to/121893/5 "2018-03-30T19:38:49Z")

</div>

Update: Vega has added [flatten transform](https://vega.github.io/vega/docs/transforms/flatten/), which will be available in Kibana 6.3, as well as in the 6.0 & 6.1 as a plugin (and hopefully I will update Vega plugin to support 6.2 soonish.
