# Pie chart - Nested data - Same document - Wrong aggregation

**URL:** https://discuss.elastic.co/t/pie-chart-nested-data-same-document-wrong-aggregation/53951
**Category:** Kibana
**Created:** [June 25, 2016, 10:39pm UTC](https://discuss.elastic.co/t/pie-chart-nested-data-same-document-wrong-aggregation/53951 "2016-06-25T22:39:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shade](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@shade](https://discuss.elastic.co/u/shade)
#### Post date: [June 25, 2016, 10:39pm UTC](https://discuss.elastic.co/t/pie-chart-nested-data-same-document-wrong-aggregation/53951/1 "2016-06-25T22:39:54Z")

</div>

i would like to know how to generate a pie chart with the following data:

themes\_subjects{  
type:nested,  
properties{  
type:nested  
theme{  
type:string  
},  
subject{  
type:string  
}  
}

example

document 1  
theme1,subject1;  
theme1,subject2;  
theme2,subject1;  
theme2,subject3;

But as I'm adding buckets and sub-buckets theme3 shouldn't become a theme1 sub-bucket, just because it's on the same document  
I'm using version 2.3.3 of elasticsearch and kibana 4.5

thanks =D

---

<div class="post-metadata">

### Author: ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)
#### Post date: [June 28, 2016, 6:18am UTC](https://discuss.elastic.co/t/pie-chart-nested-data-same-document-wrong-aggregation/53951/2 "2016-06-28T06:18:20Z")

</div>

Lucene has no concept of inner objects, so Elasticsearch flattens object hierarchies into a simple list of field names and values.

your document:

`[{ "theme": "theme1", "subject": "subject1" }, { "theme": "theme1", "subject": "subject2" }, { "theme": "theme2", "subject": "subject1" }, { "theme": "theme2", "subject": "subject3" }]`

will be transformed internally into a document that looks more like this:

`{ theme: ["theme1", "theme1", "theme2", "theme2"], subject: ["subject1", "subject2", "subject1", "subject3"] }`

Hope this helps. It sounds like you will want to create separate documents for the nested them subjects.

---

<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: [July 6, 2017, 1:49pm UTC](https://discuss.elastic.co/t/pie-chart-nested-data-same-document-wrong-aggregation/53951/3 "2017-07-06T13:49:04Z")

</div>


