# Pie chart of element count of an array

**URL:** <https://discuss.elastic.co/t/pie-chart-of-element-count-of-an-array/258612>\
**Category:** Kibana\
**Created:** [December 14, 2020, 4:35pm UTC](https://discuss.elastic.co/t/pie-chart-of-element-count-of-an-array/258612 "2020-12-14T16:35:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiclasK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niclask/32/47189_2.png) [@NiclasK](https://discuss.elastic.co/u/NiclasK)\
**Post date:** [December 14, 2020, 4:35pm UTC](https://discuss.elastic.co/t/pie-chart-of-element-count-of-an-array/258612/1 "2020-12-14T16:35:46Z")

</div>

Hi,

I'm indexing a documents that can look like this:

```auto
{
	"ProcessID": "id1",
	"ErrorList": [{
			"ErrorCode": 123,
			"Time": "2020-01-01T12:23:45"
		},
		{
			"ErrorCode": 123,
			"Time": "2020-01-01T12:44:00"
		},
		{
			"ErrorCode": 456,
			"Time": "2020-01-01T13:23:45"
		}
	]
}

```

I would like to create a pie chart that is split by ErrorCode. In this case:  
ErrorCode 123 66 % or count of 2  
ErrorCode 456 33 % or count of 1  
How can I do that? When I tried with dynamic mapping, the pie chart only report count 1.

I read [https://stackoverflow.com/questions/55503625/how-to-use-elasticsearch-nested-aggregations-in-kibana-visualizations](https://stackoverflow.com/questions/55503625/how-to-use-elasticsearch-nested-aggregations-in-kibana-visualizations) that I should use nested type, is that correct? and then use Vega chart to display the result.

Thanks!

---

<div class="post-metadata">

**Author:** ![Patrick\_Mueller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick_mueller/32/109425_2.png) [@Patrick\_Mueller](https://discuss.elastic.co/u/Patrick_Mueller)\
**Post date:** [December 15, 2020, 6:14am UTC](https://discuss.elastic.co/t/pie-chart-of-element-count-of-an-array/258612/2 "2020-12-15T06:14:21Z")

</div>

Yes, it sounds like you probably want to use the `nested` field type for `ErrorList`. I'm not sure how many visualizations are available for nested fields, but Vega is very flexible so that sounds like a good route to go down.

---

<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:** [January 12, 2021, 6:14am UTC](https://discuss.elastic.co/t/pie-chart-of-element-count-of-an-array/258612/3 "2021-01-12T06:14:25Z")

</div>

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