# Running term\_stats facets on nested mapping objects: out of memory error

**URL:** https://discuss.elastic.co/t/running-term-stats-facets-on-nested-mapping-objects-out-of-memory-error/5131
**Category:** Elasticsearch
**Created:** [August 12, 2011, 12:23am UTC](https://discuss.elastic.co/t/running-term-stats-facets-on-nested-mapping-objects-out-of-memory-error/5131 "2011-08-12T00:23:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![drv\_](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@drv\_](https://discuss.elastic.co/u/drv_)
#### Post date: [August 12, 2011, 12:23am UTC](https://discuss.elastic.co/t/running-term-stats-facets-on-nested-mapping-objects-out-of-memory-error/5131/1 "2011-08-12T00:23:03Z")

</div>

I'm having trouble getting term\_stats facets to run on documents that  
contain nested objects in the parent. The index is about 120GB in  
size, and there are around 50-100 nested objects per parent. I  
consistently get a Java heap space error, even when the query by  
itself only returns results in the low teens. I can run statistical  
facets on root object properties, but not on the nested objects.  
There are around 300k unique process names, and I'm usually winnowing  
that down to around 100k.

ElasticSearch 0.17.4 is set to use 40GB of memory, it's a single node.

My questions are:

1. Am I misunderstanding how facets run? I thought facets would only  
execute on the results produced by the query it's attached to.
2. I should be able to get around this with a script\_value in the  
facet, but what would the syntax for selecting nested document  
properties be?

gist of the general document and the types of queries I'm trying to  
run:

> <https://gist.github.com/anonymous/1141158>

Thanks for any help or pointers!  
scott

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [August 12, 2011, 2:34pm UTC](https://discuss.elastic.co/t/running-term-stats-facets-on-nested-mapping-objects-out-of-memory-error/5131/2 "2011-08-12T14:34:20Z")

</div>

Can you try and not map the nested object to be included in the parent? This  
will cause more memory used when loading the values for the field for the  
term stats.

On Fri, Aug 12, 2011 at 3:23 AM, drv\_ [scottyahoo@gmail.com](mailto:scottyahoo@gmail.com) wrote:

> I'm having trouble getting term\_stats facets to run on documents that  
> contain nested objects in the parent. The index is about 120GB in  
> size, and there are around 50-100 nested objects per parent. I  
> consistently get a Java heap space error, even when the query by  
> itself only returns results in the low teens. I can run statistical  
> facets on root object properties, but not on the nested objects.  
> There are around 300k unique process names, and I'm usually winnowing  
> that down to around 100k.
> 
> Elasticsearch 0.17.4 is set to use 40GB of memory, it's a single node.
> 
> My questions are:
> 
> 1. Am I misunderstanding how facets run? I thought facets would only  
> execute on the results produced by the query it's attached to.
> 2. I should be able to get around this with a script\_value in the  
> facet, but what would the syntax for selecting nested document  
> properties be?
> 
> gist of the general document and the types of queries I'm trying to  
> run:  
> [ElasticSearch: nested mapping, data and facet query · GitHub](https://gist.github.com/1141158)
> 
> Thanks for any help or pointers!  
> scott

---

<div class="post-metadata">

### Author: ![drv\_](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@drv\_](https://discuss.elastic.co/u/drv_)
#### Post date: [August 12, 2011, 6:29pm UTC](https://discuss.elastic.co/t/running-term-stats-facets-on-nested-mapping-objects-out-of-memory-error/5131/3 "2011-08-12T18:29:00Z")

</div>

I'll try that, thanks for the suggestion Shay. I'll let you know how  
it works after loading finishes. 🙂

Did the nested facet query look right? No obvious errors? I guess  
I'm still confused about how facets are executed, I thought they would  
run against just the result set returned by the attached query, is  
that correct? Thanks!

On Aug 12, 7:34 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Can you try and not map the nested object to be included in the parent? This  
> will cause more memory used when loading the values for the field for the  
> term stats.
> 
> On Fri, Aug 12, 2011 at 3:23 AM, drv\_ [scottya...@gmail.com](mailto:scottya...@gmail.com) wrote:
> 
> > I'm having trouble getting term\_stats facets to run on documents that  
> > contain nested objects in the parent. The index is about 120GB in  
> > size, and there are around 50-100 nested objects per parent. I  
> > consistently get a Java heap space error, even when the query by  
> > itself only returns results in the low teens. I can run statistical  
> > facets on root object properties, but not on the nested objects.  
> > There are around 300k unique process names, and I'm usually winnowing  
> > that down to around 100k.
> 
> > Elasticsearch 0.17.4 is set to use 40GB of memory, it's a single node.
> 
> > My questions are:
> > 
> > 1. Am I misunderstanding how facets run? I thought facets would only  
> > execute on the results produced by the query it's attached to.
> > 2. I should be able to get around this with a script\_value in the  
> > facet, but what would the syntax for selecting nested document  
> > properties be?
> 
> > gist of the general document and the types of queries I'm trying to  
> > run:  
> > [ElasticSearch: nested mapping, data and facet query · GitHub](https://gist.github.com/1141158)
> 
> > Thanks for any help or pointers!  
> > scott

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [August 12, 2011, 9:59pm UTC](https://discuss.elastic.co/t/running-term-stats-facets-on-nested-mapping-objects-out-of-memory-error/5131/4 "2011-08-12T21:59:18Z")

</div>

The facet will only run against the result of the query, but, all the values  
for those fields will be loaded to memory for fast facet calculation.

On Fri, Aug 12, 2011 at 9:29 PM, drv\_ [scottyahoo@gmail.com](mailto:scottyahoo@gmail.com) wrote:

> I'll try that, thanks for the suggestion Shay. I'll let you know how  
> it works after loading finishes. 🙂
> 
> Did the nested facet query look right? No obvious errors? I guess  
> I'm still confused about how facets are executed, I thought they would  
> run against just the result set returned by the attached query, is  
> that correct? Thanks!
> 
> On Aug 12, 7:34 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Can you try and not map the nested object to be included in the parent?  
> > This  
> > will cause more memory used when loading the values for the field for the  
> > term stats.
> > 
> > On Fri, Aug 12, 2011 at 3:23 AM, drv\_ [scottya...@gmail.com](mailto:scottya...@gmail.com) wrote:
> > 
> > > I'm having trouble getting term\_stats facets to run on documents that  
> > > contain nested objects in the parent. The index is about 120GB in  
> > > size, and there are around 50-100 nested objects per parent. I  
> > > consistently get a Java heap space error, even when the query by  
> > > itself only returns results in the low teens. I can run statistical  
> > > facets on root object properties, but not on the nested objects.  
> > > There are around 300k unique process names, and I'm usually winnowing  
> > > that down to around 100k.
> > 
> > > Elasticsearch 0.17.4 is set to use 40GB of memory, it's a single node.
> > 
> > > My questions are:
> > > 
> > > 1. Am I misunderstanding how facets run? I thought facets would only  
> > > execute on the results produced by the query it's attached to.
> > > 2. I should be able to get around this with a script\_value in the  
> > > facet, but what would the syntax for selecting nested document  
> > > properties be?
> > 
> > > gist of the general document and the types of queries I'm trying to  
> > > run:  
> > > [ElasticSearch: nested mapping, data and facet query · GitHub](https://gist.github.com/1141158)
> > 
> > > Thanks for any help or pointers!  
> > > scott

---

<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, 3:57am UTC](https://discuss.elastic.co/t/running-term-stats-facets-on-nested-mapping-objects-out-of-memory-error/5131/5 "2017-07-06T03:57:15Z")

</div>


