# Pie chart aggregating elements of an array field

**URL:** <https://discuss.elastic.co/t/pie-chart-aggregating-elements-of-an-array-field/157107>\
**Category:** Kibana\
**Created:** [November 16, 2018, 4:55pm UTC](https://discuss.elastic.co/t/pie-chart-aggregating-elements-of-an-array-field/157107 "2018-11-16T16:55:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [November 16, 2018, 4:55pm UTC](https://discuss.elastic.co/t/pie-chart-aggregating-elements-of-an-array-field/157107/1 "2018-11-16T16:55:49Z")

</div>

Hi there,

I have the following situation:

1 - My index mapping contains:

```
 "my_array": {
         "properties": {
                 "desc": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } },
                 "percent": { "type": "half_float" },
                 "quantity": { "type": "integer" },
                 "code": { "type": "keyword" }
         }
 }

```

A sample document in my index would look like that:

```
"my_array": [
{ 
	"code": "a1", "desc": "abc", "quantity": "4", "percent": "7.7"
},
{ 
	"code": "a2", "desc": "abc", "quantity": "6", "percent": "12"
},
{
	"code": "b", "desc": "xyz", "quantity": "12", "percent": "23"
},
{
	"code": "c", "desc": "xyz", "quantity": "11", "percent": "21"
},
{
	"code": "d1", "desc": "cde", "quantity": "5", "percent": "9.6"
},
{
	"code": "d2", "desc": "cde", "quantity": "14", "percent": "26.9"
},
{
	"code": "e", "desc": "xyz", "quantity": "0", "percent": "0"
}

```

I'm trying to make a pie chart in kibana with 3 slices:  
1 - The sum of all my\_array.desc='abc' quantity;  
2 - The sum of all my.array.desc='xyz' quantity;  
3 - The sum of my.array.desc='cde' quantity.

I've made the following setting:

- The slice size aggregation is: SUM (field: my\_array.quantity)

- The split slice bucket is: Terms (field: my\_array.desc.keyword)

I was expecting three slices, each one containing the sum of the respective my\_array.quantity values. But it's returning three **equal** slices, which one having the sum of all the my\_array.quantity values. It seems it's not considering the terms aggregation to calculate.

![11](https://us1.discourse-cdn.com/elastic/original/3X/0/4/04dd9d2b96a2b8e8ced7f2e6eb33ef85fc534852.png)

Does anybody know what I'm doing wrong? Does it have to do with my mapping structure?

Thanks

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [November 16, 2018, 9:00pm UTC](https://discuss.elastic.co/t/pie-chart-aggregating-elements-of-an-array-field/157107/2 "2018-11-16T21:00:28Z")

</div>

I've got it. I need to map the field `:my_array` with `type: nested`.

Thanks

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [November 16, 2018, 10:38pm UTC](https://discuss.elastic.co/t/pie-chart-aggregating-elements-of-an-array-field/157107/3 "2018-11-16T22:38:31Z")

</div>

Thanks for circling back with your solutions.

Cheers  
Rashmi

---

<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:** [December 14, 2018, 10:38pm UTC](https://discuss.elastic.co/t/pie-chart-aggregating-elements-of-an-array-field/157107/4 "2018-12-14T22:38:36Z")

</div>

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