# How can I visualize aggregation results using Vega?

**URL:** <https://discuss.elastic.co/t/how-can-i-visualize-aggregation-results-using-vega/342907>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [September 13, 2023, 6:56am UTC](https://discuss.elastic.co/t/how-can-i-visualize-aggregation-results-using-vega/342907 "2023-09-13T06:56:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carollyl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carollyl/32/120726_2.png) [@carollyl](https://discuss.elastic.co/u/carollyl)\
**Post date:** [September 13, 2023, 6:56am UTC](https://discuss.elastic.co/t/how-can-i-visualize-aggregation-results-using-vega/342907/1 "2023-09-13T06:56:03Z")

</div>

I'm a newbie to Vega. Appreciate it if you can help me to build a visualizer on the aggregated results that I have as follows.  
For every `release`, I'd like to show the sum of duration per `workflow` (e.g., A, B, and C) based on the latest `id`.

Sample dataset:

```auto
release,id,workflow,sid,duration
1.0,1,A,x1,1
1.0,1,A,x2,6
1.0,2,A,x1,2
1.0,2,A,x2,3
1.0,1,B,y1,1
1.0,1,B,y2,2
1.0,2,B,y1,8
1.0,2,B,y2,3
1.0,3,B,y1,4
1.0,3,B,y2,2
1.1,1,A,x1,1
1.1,1,A,x2,6
1.1,2,A,x1,2
1.1,2,A,x2,4
1.2,1,C,y1,3
1.2,1,C,y2,2
1.2,2,C,y1,8
1.2,2,C,y2,3
1.2,4,C,y1,9
1.2,4,C,y2,7

```

Query:

```auto
GET discuss-duration/_search
{
  "size": 0,
  "aggs": {
    "workflow": {
      "terms": {
        "field": "workflow"
      },
      "aggs": {
        "ids": {
          "terms": {
            "field": "id",
            "order": { "max_id": "desc" },
            "size": 1
          },
          "aggs": {
            "max_id": {
              "max": {
                "field": "id"
              }
            },
            "sum_duration": {
              "sum": {
                "field": "duration"
              }
            }
          }
        }
      }
    }
  }
}

```

Results:

```auto
# Results
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "workflow": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "B",
          "doc_count": 6,
          "ids": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 4,
            "buckets": [
              {
                "key": 3,
                "doc_count": 2,
                "sum_duration": {
                  "value": 6
                },
                "max_id": {
                  "value": 3
                }
              }
            ]
          }
        },
        {
          "key": "A",
          "doc_count": 4,
          "ids": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 2,
            "buckets": [
              {
                "key": 2,
                "doc_count": 2,
                "sum_duration": {
                  "value": 5
                },
                "max_id": {
                  "value": 2
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![carollyl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carollyl/32/120726_2.png) [@carollyl](https://discuss.elastic.co/u/carollyl)\
**Post date:** [September 16, 2023, 6:50am UTC](https://discuss.elastic.co/t/how-can-i-visualize-aggregation-results-using-vega/342907/2 "2023-09-16T06:50:23Z")

</div>

I managed to create bar chart with Vega using the aggregated results.

---

<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:** [October 14, 2023, 6:50am UTC](https://discuss.elastic.co/t/how-can-i-visualize-aggregation-results-using-vega/342907/3 "2023-10-14T06:50:54Z")

</div>

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