# Out Of Memory during the terms facets

**URL:** <https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068>\
**Category:** Elasticsearch\
**Created:** [March 8, 2013, 3:33am UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068 "2013-03-08T03:33:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Curt\_Hu](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@Curt\_Hu](https://discuss.elastic.co/u/Curt_Hu)\
**Post date:** [March 8, 2013, 3:33am UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/1 "2013-03-08T03:33:16Z")

</div>

Actually, it's very strange for me to encounter this problem:

Index name: surfikisemterms

Index mapping:  
{"surfikisemterms":{"jdbc\_search":{"properties":{"facets":{"dynamic":"true","properties":{"termscount":{"dynamic":"true","properties":{"terms":{"dynamic":"true","properties":{"field":{"type":"string"},"size":{"type":"long"}}}}}}},"from":{"type":"long"},"query":{"dynamic":"true","properties":{"bool":{"dynamic":"true","properties":{"must":{"dynamic":"true","properties":{"query\_string":{"dynamic":"true","properties":{"query":{"type":"string"}}}}}}}}},"size":{"type":"long"}}},"jdbc":{"properties":{"keywords":{"type":"string","analyzer":"comma"},"time":{"type":"date","format":"dateOptionalTime"}}}}}

Index setting:  
{"surfikisemterms":{"settings":{"index.analysis.tokenizer.commatokenizer.type":"pattern","index.analysis.analyzer.comma.type":"custom","index.number\_of\_replicas":"1","index.version.created":"200599","index.analysis.tokenizer.commatokenizer.pattern":",","index.analysis.analyzer.comma.tokenizer":"commatokenizer","index.number\_of\_shards":"5"}}}

So actually we only have 2 fields for the index, keywords which is a word list and time is the timestamp.

I have 3 nodes in cluster: with all environment variables:  
ES\_HEAP\_SIZE=3000M  
ES\_MIN\_MEM=3000M  
ES\_MAX\_MEM=3000M

Then, if a do a query like:  
{  
"query": {  
"bool": {  
"must": [  
{  
"range": {  
"time": {  
"from": "2013-03-07T11:29:19.000Z",  
"to": "2013-03-07T11:30:19.000Z"  
}  
}  
}  
],  
"must\_not": [],  
"should": []  
}  
},  
"from": 0,  
"size": 10,  
"sort": [],  
"facets": {}  
}

Totally I shall get 21 hits, and it returns so fast. among these hits, there is no one hit could contain more than 40 keywords..

Then if I do:  
{  
"query": {  
"bool": {  
"must": [  
{  
"range": {  
"time": {  
"from": "2013-03-07T11:29:19.000Z",  
"to": "2013-03-07T11:30:19.000Z"  
}  
}  
}  
],  
"must\_not": [],  
"should": []  
}  
},  
"from": 0,  
"size": 22,  
"sort": [],  
"facets": {  
"termscount": {  
"terms": {  
"field": "keywords",  
"size": 25  
}  
}  
}  
}  
I can see following logs repeating for several time:

[2013-03-08 03:31:05,571][WARN][index.cache.field.data.resident] [Surfiki Master: Bobby Hutcherson] [surfikisemterms] loading field [keywords] caused out of memory failure  
java.lang.OutOfMemoryError: Java heap space..

What I got confused is for above query, the hit docs only contain no more than 500 keywords, why do such terms facet shall make out of memory error?

Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2013, 7:25am UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/2 "2013-03-08T07:25:11Z")

</div>

Hi,

Could you create a full curl recreation and GIST it?  
On which ES version are you working?  
Which java version?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 8 mars 2013 à 04:33, Curt Hu [zhongting.hu@gmail.com](mailto:zhongting.hu@gmail.com) a écrit :

Actually, it's very strange for me to encounter this problem:

Index name: surfikisemterms

Index mapping:  
{"surfikisemterms":{"jdbc\_search":{"properties":{"facets":{"dynamic":"true","properties":{"termscount":{"dynamic":"true","properties":{"terms":{"dynamic":"true","properties":{"field":{"type":"string"},"size":{"type":"long"}}}}}}},"from":{"type":"long"},"query":{"dynamic":"true","properties":{"bool":{"dynamic":"true","properties":{"must":{"dynamic":"true","properties":{"query\_string":{"dynamic":"true","properties":{"query":{"type":"string"}}}}}}}}},"size":{"type":"long"}}},"jdbc":{"properties":{"keywords":{"type":"string","analyzer":"comma"},"time":{"type":"date","format":"dateOptionalTime"}}}}}

Index setting:  
{"surfikisemterms":{"settings":{"index.analysis.tokenizer.commatokenizer.type":"pattern","index.analysis.analyzer.comma.type":"custom","index.number\_of\_replicas":"1","index.version.created":"200599","index.analysis.tokenizer.commatokenizer.pattern":",","index.analysis.analyzer.comma.tokenizer":"commatokenizer","index.number\_of\_shards":"5"}}}

So actually we only have 2 fields for the index, keywords which is a word  
list and time is the timestamp.

I have 3 nodes in cluster: with all environment variables:  
ES\_HEAP\_SIZE=3000M  
ES\_MIN\_MEM=3000M  
ES\_MAX\_MEM=3000M

Then, if a do a query like:  
{  
"query": {  
"bool": {  
"must": [  
{  
"range": {  
"time": {  
"from": "2013-03-07T11:29:19.000Z",  
"to": "2013-03-07T11:30:19.000Z"  
}  
}  
}  
],  
"must\_not": [],  
"should": []  
}  
},  
"from": 0,  
"size": 10,  
"sort": [],  
"facets": {}  
}

Totally I shall get 21 hits, and it returns so fast. among these hits, there  
is no one hit could contain more than 40 keywords..

Then if I do:  
{  
"query": {  
"bool": {  
"must": [  
{  
"range": {  
"time": {  
"from": "2013-03-07T11:29:19.000Z",  
"to": "2013-03-07T11:30:19.000Z"  
}  
}  
}  
],  
"must\_not": [],  
"should": []  
}  
},  
"from": 0,  
"size": 22,  
"sort": [],  
"facets": {  
"termscount": {  
"terms": {  
"field": "keywords",  
"size": 25  
}  
}  
}  
}  
I can see following logs repeating for several time:

[2013-03-08 03:31:05,571][WARN][index.cache.field.data.resident] [Surfiki  
Master: Bobby Hutcherson] [surfikisemterms] loading field [keywords] caused  
out of memory failure  
java.lang.OutOfMemoryError: Java heap space..

What I got confused is for above query, the hit docs only contain no more  
than 500 keywords, why do such terms facet shall make out of memory error?

Thanks.

--  
View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285.html](http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285.html)  
Sent from the ElasticSearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [March 8, 2013, 7:37am UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/3 "2013-03-08T07:37:37Z")

</div>

Hi,

The following thread might help you.  
[https://groups.google.com/forum/#!topic/elasticsearch/4Uxbmy-e1ao](https://groups.google.com/forum/#!topic/elasticsearch/4Uxbmy-e1ao)

-- Sujoy.

On Friday, March 8, 2013 9:03:16 AM UTC+5:30, Curt wrote:

> Actually, it's very strange for me to encounter this problem:
> 
> Index name: surfikisemterms
> 
> Index mapping:  
> {"surfikisemterms":{"jdbc\_search":{"properties":{"facets":{"dynamic":"true","properties":{"termscount":{"dynamic":"true","properties":{"terms":{"dynamic":"true","properties":{"field":{"type":"string"},"size":{"type":"long"}}}}}}},"from":{"type":"long"},"query":{"dynamic":"true","properties":{"bool":{"dynamic":"true","properties":{"must":{"dynamic":"true","properties":{"query\_string":{"dynamic":"true","properties":{"query":{"type":"string"}}}}}}}}},"size":{"type":"long"}}},"jdbc":{"properties":{"keywords":{"type":"string","analyzer":"comma"},"time":{"type":"date","format":"dateOptionalTime"}}}}}
> 
> Index setting:  
> {"surfikisemterms":{"settings":{"index.analysis.tokenizer.commatokenizer.type":"pattern","index.analysis.analyzer.comma.type":"custom","index.number\_of\_replicas":"1","index.version.created":"200599","index.analysis.tokenizer.commatokenizer.pattern":",","index.analysis.analyzer.comma.tokenizer":"commatokenizer","index.number\_of\_shards":"5"}}}
> 
> So actually we only have 2 fields for the index, keywords which is a word  
> list and time is the timestamp.
> 
> I have 3 nodes in cluster: with all environment variables:  
> ES\_HEAP\_SIZE=3000M  
> ES\_MIN\_MEM=3000M  
> ES\_MAX\_MEM=3000M
> 
> Then, if a do a query like:  
> {  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "range": {  
> "time": {  
> "from": "2013-03-07T11:29:19.000Z",  
> "to": "2013-03-07T11:30:19.000Z"  
> }  
> }  
> }  
> ],  
> "must\_not": ,  
> "should":   
> }  
> },  
> "from": 0,  
> "size": 10,  
> "sort": ,  
> "facets": {}  
> }
> 
> Totally I shall get 21 hits, and it returns so fast. among these hits,  
> there  
> is no one hit could contain more than 40 keywords..
> 
> Then if I do:  
> {  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "range": {  
> "time": {  
> "from": "2013-03-07T11:29:19.000Z",  
> "to": "2013-03-07T11:30:19.000Z"  
> }  
> }  
> }  
> ],  
> "must\_not": ,  
> "should":   
> }  
> },  
> "from": 0,  
> "size": 22,  
> "sort": ,  
> "facets": {  
> "termscount": {  
> "terms": {  
> "field": "keywords",  
> "size": 25  
> }  
> }  
> }  
> }  
> I can see following logs repeating for several time:
> 
> [2013-03-08 03:31:05,571][WARN][index.cache.field.data.resident] [Surfiki  
> Master: Bobby Hutcherson] [surfikisemterms] loading field [keywords]  
> caused  
> out of memory failure  
> java.lang.OutOfMemoryError: Java heap space..
> 
> What I got confused is for above query, the hit docs only contain no more  
> than 500 keywords, why do such terms facet shall make out of memory error?
> 
> Thanks.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285.html](http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Curt\_Hu](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@Curt\_Hu](https://discuss.elastic.co/u/Curt_Hu)\
**Post date:** [March 8, 2013, 10:31am UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/4 "2013-03-08T10:31:31Z")

</div>

Hi, update gist here:

> <https://gist.github.com/BlueStalker/5115578>

Please tell me if I have missed anything. Great thanks for help.

---

<div class="post-metadata">

**Author:** ![Curt\_Hu](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@Curt\_Hu](https://discuss.elastic.co/u/Curt_Hu)\
**Post date:** [March 11, 2013, 2:05pm UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/5 "2013-03-11T14:05:06Z")

</div>

Hello , guys.

Is any update for this issue?  
Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 11, 2013, 2:57pm UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/6 "2013-03-11T14:57:25Z")

</div>

Hi,

You need more memory to let Elasticsearch load all different values in cache.  
You should try to run it with 0.90.0.Beta1 as the memory footprint has been reduced.

You can also redesign your index for example by dates. It will reduce the number of terms to load in memory.  
It depends here on your use case. Sounds like your filter applies on a single day. So, an index per day?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 8 mars 2013 à 11:31, Curt Hu [zhongting.hu@gmail.com](mailto:zhongting.hu@gmail.com) a écrit :

> Hi, update gist here:  
> [Terms Facets with few hits got Elastic Out Of Memory Error. · GitHub](https://gist.github.com/BlueStalker/5115578)
> 
> Please tell me if I have missed anything. Great thanks for help.
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031305.html](http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031305.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Curt\_Hu](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@Curt\_Hu](https://discuss.elastic.co/u/Curt_Hu)\
**Post date:** [March 13, 2013, 2:54am UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/7 "2013-03-13T02:54:13Z")

</div>

Hi,

Actually, how Elasticsearch implements the terms facets. You were talking about loading all different values in cache, what 's the mechanism..

In my real example, the query will filter the index within several minutes, which cause only about 20 docs in total hits, and the total terms are no more than 500.. It should be a limited number to do any type of sort..

Thanks.

Hi,

You need more memory to let Elasticsearch load all different values in cache.  
You should try to run it with 0.90.0.Beta1 as the memory footprint has been reduced.

You can also redesign your index for example by dates. It will reduce the number of terms to load in memory.  
It depends here on your use case. Sounds like your filter applies on a single day. So, an index per day?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 8 mars 2013 à 11:31, Curt Hu \<zhongting.hu@\> a écrit :

> Hi, update gist here:  
> [Terms Facets with few hits got Elastic Out Of Memory Error. · GitHub](https://gist.github.com/BlueStalker/5115578)
> 
> Please tell me if I have missed anything. Great thanks for help.
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031305.html](http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031305.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@.  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 13, 2013, 1:04pm UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/8 "2013-03-13T13:04:11Z")

</div>

On Tue, 2013-03-12 at 19:54 -0700, Curt Hu wrote:

> Hi,
> 
> Actually, how Elasticsearch implements the terms facets. You were talking  
> about loading all different values in cache, what 's the mechanism..
> 
> In my real example, the query will filter the index within several minutes,  
> which cause only about 20 docs in total hits, and the total terms are no  
> more than 500.. It should be a limited number to do any type of sort..

If you need the field values for docs 1,2 and 3 for this query, you're  
probably going to need the values for doc 4,5 and 6 at some stage in the  
future.

So the most efficient thing to do is to load the field values for all  
docs into memory in one go. Then they're available for future requests  
without having to reload.

So unfortunately, even if your query matches just a few docs, you need  
space on your heap for the values from all docs.

clint

> Thanks.
> 
> dadoonet wrote
> 
> > Hi,
> > 
> > You need more memory to let Elasticsearch load all different values in  
> > cache.  
> > You should try to run it with 0.90.0.Beta1 as the memory footprint has  
> > been reduced.
> > 
> > You can also redesign your index for example by dates. It will reduce the  
> > number of terms to load in memory.  
> > It depends here on your use case. Sounds like your filter applies on a  
> > single day. So, an index per day?
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 8 mars 2013 à 11:31, Curt Hu \<
> 
> > zhongting.hu@
> 
> > \> a écrit :
> > 
> > > Hi, update gist here:  
> > > [Terms Facets with few hits got Elastic Out Of Memory Error. · GitHub](https://gist.github.com/BlueStalker/5115578)
> > > 
> > > Please tell me if I have missed anything. Great thanks for help.
> > > 
> > > --  
> > > View this message in context:  
> > > [http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031305.html](http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031305.html)  
> > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to
> 
> > elasticsearch+unsubscribe@
> 
> > .
> > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to
> 
> > elasticsearch+unsubscribe@
> 
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031542.html](http://elasticsearch-users.115913.n3.nabble.com/Out-Of-Memory-during-the-terms-facets-tp4031285p4031542.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:46am UTC](https://discuss.elastic.co/t/out-of-memory-during-the-terms-facets/11068/9 "2017-07-06T02:46:44Z")

</div>


