# Facet query on nested structure - Out of memory exception

**URL:** https://discuss.elastic.co/t/facet-query-on-nested-structure-out-of-memory-exception/10397
**Category:** Elasticsearch
**Created:** [January 17, 2013, 8:20pm UTC](https://discuss.elastic.co/t/facet-query-on-nested-structure-out-of-memory-exception/10397 "2013-01-17T20:20:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ash\_2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ash\_2](https://discuss.elastic.co/u/Ash_2)
#### Post date: [January 17, 2013, 8:20pm UTC](https://discuss.elastic.co/t/facet-query-on-nested-structure-out-of-memory-exception/10397/1 "2013-01-17T20:20:00Z")

</div>

Hi all,

I've been trying to query facets on nested structures on a very small index  
of around 14,000 documents, each containing around 100 nested docs.

The indexed documents look similar to this, with many elements in the color  
array.  
{  
"color": [  
{  
"name": "n3",  
"value": "v3",  
"type": "t3"  
},  
{  
"name": "n4",  
"value": "v4",  
"type": "t4"  
}  
]  
}

My index mapping specifies that blue is nested and all strings are  
not\_analyzed.  
Running a simple facet query like the one below on around 4,000 documents,  
uses around 700MB of heap space (spikes to 700 MB from 300 MB and lots of  
activity on garbage collection). Doing the same query on 14,000 documents,  
the heap memory usage spikes to 3GB (that is my max right now) and  
Elasticsearch throws an OutOfMemoryException. I've tried settingindex.cache.field.type: soft to  
no avail.

{  
"size": 0,  
"facets": {  
"fname": {  
"terms": {  
"field": "color.name"  
}  
}  
}  
}

Another interesting behavior is that if I don't specify a nested mapping  
for the index, the facets return with little memory usage.

So, is this the typical behavior for 14,000 indexed documents with nested  
docs?

Note: index has five shards and one replica.

I would greatly appreciate you help.

--

---

<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, 2:55am UTC](https://discuss.elastic.co/t/facet-query-on-nested-structure-out-of-memory-exception/10397/2 "2017-07-06T02:55:51Z")

</div>


