# Why to cause OOM when searching with query and facet?

**URL:** <https://discuss.elastic.co/t/why-to-cause-oom-when-searching-with-query-and-facet/14003>\
**Category:** Elasticsearch\
**Created:** [October 18, 2013, 2:01am UTC](https://discuss.elastic.co/t/why-to-cause-oom-when-searching-with-query-and-facet/14003 "2013-10-18T02:01:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Min\_Cha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/min_cha/32/1131_2.png) [@Min\_Cha](https://discuss.elastic.co/u/Min_Cha)\
**Post date:** [October 18, 2013, 2:01am UTC](https://discuss.elastic.co/t/why-to-cause-oom-when-searching-with-query-and-facet/14003/1 "2013-10-18T02:01:23Z")

</div>

Hi folks.

I am a newbie to ES.  
My goal is to compute recommendation music list for a user.  
The commendation music is simply musics which the user`s friends listened  
to.

For that, I have added about 10,000,000 documents as following mapping.

properties: {  
follows: {  
type: "string"  
},  
id: {  
type: "string"  
},  
name: {  
type: "string"  
},  
plays: {  
properties: {  
count: {  
type: "long"  
},  
lastPlayed: {  
type: "string"  
},  
musicId: {  
type: "string"  
}}}  
}

Then, I have searched as following.

{"size":0,"query":{"field":{"follows":"2324"}},"facets":{"plays":{"terms":{"size":10,"script":"doc['plays.musicId'].values"}}}}

I expected search cost as "O(log n \* friend count of '2344')" and then  
facet computing cost on searched friends docs.  
But when I run above query, OutOfMemory occurs as following.

reason:  
RemoteTransportException[[m4][inet[/10.99.195.57:9300]][search/phase/query]];  
nested: QueryPhaseExecutionException[[music][1]:  
query[id:2324],from[0],size[0]: Query Failed [Failed to execute main  
query]]; nested: ElasticSearchException[java.lang.OutOfMemoryError: Java  
heap space]; nested: ExecutionError[java.lang.OutOfMemoryError: Java heap  
space]; nested: OutOfMemoryError[Java heap space];

Who can I help me? Please give me some advice.  
Thanks for reading.

--  
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:** ![Min\_Cha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/min_cha/32/1131_2.png) [@Min\_Cha](https://discuss.elastic.co/u/Min_Cha)\
**Post date:** [October 18, 2013, 2:04am UTC](https://discuss.elastic.co/t/why-to-cause-oom-when-searching-with-query-and-facet/14003/2 "2013-10-18T02:04:36Z")

</div>

Sorry. 'follows' is List. 'plays' is also List.

2013년 10월 18일 금요일 오전 11시 1분 23초 UTC+9, Min Cha 님의 말:

> Hi folks.
> 
> I am a newbie to ES.  
> My goal is to compute recommendation music list for a user.  
> The commendation music is simply musics which the user`s friends listened  
> to.
> 
> For that, I have added about 10,000,000 documents as following mapping.
> 
> properties: {  
> follows: {  
> type: "string"  
> },  
> id: {  
> type: "string"  
> },  
> name: {  
> type: "string"  
> },  
> plays: {  
> properties: {  
> count: {  
> type: "long"  
> },  
> lastPlayed: {  
> type: "string"  
> },  
> musicId: {  
> type: "string"  
> }}}  
> }
> 
> Then, I have searched as following.
> 
> {"size":0,"query":{"field":{"follows":"2324"}},"facets":{"plays":{"terms":{"size":10,"script":"doc['plays.musicId'].values"}}}}
> 
> I expected search cost as "O(log n \* friend count of '2344')" and then  
> facet computing cost on searched friends docs.  
> But when I run above query, OutOfMemory occurs as following.
> 
> reason:  
> RemoteTransportException[[m4][inet[/10.99.195.57:9300]][search/phase/query]];  
> nested: QueryPhaseExecutionException[[music][1]:  
> query[id:2324],from[0],size[0]: Query Failed [Failed to execute main  
> query]]; nested: ElasticSearchException[java.lang.OutOfMemoryError: Java  
> heap space]; nested: ExecutionError[java.lang.OutOfMemoryError: Java heap  
> space]; nested: OutOfMemoryError[Java heap space];
> 
> Who can I help me? Please give me some advice.  
> Thanks for reading.

--  
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:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 20, 2013, 3:35pm UTC](https://discuss.elastic.co/t/why-to-cause-oom-when-searching-with-query-and-facet/14003/3 "2013-10-20T15:35:15Z")

</div>

Hey,

two notes: First, by default only 1 GB of memory is used by the JVM when  
starting up. You can change this using the ES\_HEAP\_SIZE parameter. See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Second, you should not facet on an analyzed field, but set the field you  
want to facet on to not\_analyzed. If you need to search on that field as  
well, consider using a multi field, see

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

The first link also explains a bit, why you should not facet on an analyzed  
field.

As a last hint, you should monitor the size of your fielddata in order to  
prevent out of memory exceptions, see

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Hope this helps... When in doubt, always ask 🙂

--Alex

On Fri, Oct 18, 2013 at 4:04 AM, Min Cha [minslovey@gmail.com](mailto:minslovey@gmail.com) wrote:

> Sorry. 'follows' is List. 'plays' is also List.
> 
> 2013년 10월 18일 금요일 오전 11시 1분 23초 UTC+9, Min Cha 님의 말:
> 
> > Hi folks.
> > 
> > I am a newbie to ES.  
> > My goal is to compute recommendation music list for a user.  
> > The commendation music is simply musics which the user`s friends listened  
> > to.
> > 
> > For that, I have added about 10,000,000 documents as following mapping.
> > 
> > properties: {  
> > follows: {  
> > type: "string"  
> > },  
> > id: {  
> > type: "string"  
> > },  
> > name: {  
> > type: "string"  
> > },  
> > plays: {  
> > properties: {  
> > count: {  
> > type: "long"  
> > },  
> > lastPlayed: {  
> > type: "string"  
> > },  
> > musicId: {  
> > type: "string"  
> > }}}  
> > }
> > 
> > Then, I have searched as following.
> > 
> > {"size":0,"query":{"field":{" **follows":"2324"}},"facets":{"**  
> > plays":{"terms":{"size":10,"\*\*script":"doc['plays.musicId'].\*\*values"}}}}
> > 
> > I expected search cost as "O(log n \* friend count of '2344')" and then  
> > facet computing cost on searched friends docs.  
> > But when I run above query, OutOfMemory occurs as following.
> > 
> > reason: RemoteTransportException[[m4][\*\*inet[/10.99.195.57:9300]][\*\*search/phase/query]];  
> > nested: QueryPhaseExecutionException[[**music][1]:  
> > query[id:2324],from[0],size[0]**: Query Failed [Failed to execute main  
> > query]]; nested: ElasticSearchException[java.\*\*lang.OutOfMemoryError:  
> > Java heap space]; nested: ExecutionError[java.lang.\*\*OutOfMemoryError:  
> > Java heap space]; nested: OutOfMemoryError[Java heap space];
> > 
> > Who can I help me? Please give me some advice.  
> > Thanks for reading.
> > 
> > --  
> > 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:** ![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:11am UTC](https://discuss.elastic.co/t/why-to-cause-oom-when-searching-with-query-and-facet/14003/4 "2017-07-06T02:11:35Z")

</div>


