# NestedType - DISTINCT COUNT - Flattened Data - Performance

**URL:** <https://discuss.elastic.co/t/nestedtype-distinct-count-flattened-data-performance/43437>\
**Category:** Elasticsearch\
**Created:** [March 3, 2016, 8:15pm UTC](https://discuss.elastic.co/t/nestedtype-distinct-count-flattened-data-performance/43437 "2016-03-03T20:15:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthik\_Ramachandran](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@Karthik\_Ramachandran](https://discuss.elastic.co/u/Karthik_Ramachandran)\
**Post date:** [March 3, 2016, 8:15pm UTC](https://discuss.elastic.co/t/nestedtype-distinct-count-flattened-data-performance/43437/1 "2016-03-03T20:15:29Z")

</div>

We have mapping where lot of nested type is already present. I thought of removing nested by doing Actual\*Nested viz. Flattening. But it explodes data like anything. Moreover, to define the correct aggregation metric on search, we need to provide distinct count on a specific attribute key. I have concerns on this. It would be helpful if someone could clarify.

Case below:

{  
myJSONKey:  
Attr1:  
Attr2: \<\>  
....  
,NestedType1 :{  
[Array of objects having Attr1, Attr2...]   
}  
,NestedType2 :{  
[Array of objects having Attr1, Attr2...]   
}  
}

Convert to  
{  
myJSONKey:  
Attr1:  
Attr2: \<\>  
NestedType1.Attr1: NOTE: It is not array of attr1 values. Each value will ahve its own index explicitly specified  
NestedType1.Attr2:  
NestedType2.Attr1:  
NestedType2.Attr2:  
}

I could also think of moving Attr2 to a separate Index for Full Text search thus reduce index size. But If I have to combine query and filter, it would be an issue. All my needs are Query+Filter and create aggregations over a year etc.

My Anticipated Volume is 7300 Million entries per year when I have nested types. If I flatten it, it may explode to 7300 Million \* 15 times -and will end up doing DISTINCT count to get accurate document count.

Any thoughts on this would be helpful

---

<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 5, 2017, 11:11pm UTC](https://discuss.elastic.co/t/nestedtype-distinct-count-flattened-data-performance/43437/2 "2017-07-05T23:11:28Z")

</div>


