# How to improve facet performance?

**URL:** <https://discuss.elastic.co/t/how-to-improve-facet-performance/14006>\
**Category:** Elasticsearch\
**Created:** [October 18, 2013, 5:05am UTC](https://discuss.elastic.co/t/how-to-improve-facet-performance/14006 "2013-10-18T05:05:23Z")\
**Posts on this page:** 5\
**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, 5:05am UTC](https://discuss.elastic.co/t/how-to-improve-facet-performance/14006/1 "2013-10-18T05:05:23Z")

</div>

[https://groups.google.com/forum/#!topic/elasticsearch/3j\_r5uc\_7F4](https://groups.google.com/forum/#!topic/elasticsearch/3j_r5uc_7F4)

Hello.  
I had the OOM problem and resolved by setting option  
'index.cache.field.type: soft'.  
At now, my query and facet works file.

But I have faced new problem, pool performance.

For example,

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

For testing, I changed facet field as following.

Req : {"size":0,"query":{"field":{"follows":"2324"}},"facets":{"  
plays":{"terms":{"size":10,"script":"doc['plays.count'].values"}}}}  
Res : {took : 5 ...}

This change makes performance good dramatically.  
The difference between 'musicId' and 'count' is one.

1. The count value of all docs is 1.(constant)
2. The musicId value of each doc is between 1 and 50000 and each doc has  
300 musicIds.

There is an way to improve performance?  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [October 18, 2013, 5:34pm UTC](https://discuss.elastic.co/t/how-to-improve-facet-performance/14006/2 "2013-10-18T17:34:37Z")

</div>

Hiya

Hello.

> I had the OOM problem and resolved by setting option  
> 'index.cache.field.type: soft'.  
> At now, my query and facet works file.
> 
> But I have faced new problem, pool performance.

That's what `soft` gives you 🙂 By using soft references, you haven't  
solved the OOM problem, you've just forced ES to reload field data all the  
time (which is very heavy).

You can set the indices.fielddata.cache.size size to avoid OOMs, but it's a  
safety mechanism, not a solution. If you are running out of memory it'll  
evict field data, which will affect performance. 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.

You need more memory, or more nodes, or fewer facets. If you're faceting on  
high cardinality string fields, that's going to use a lot of memory.

clint

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [October 18, 2013, 6:07pm UTC](https://discuss.elastic.co/t/how-to-improve-facet-performance/14006/3 "2013-10-18T18:07:03Z")

</div>

Instead of using scripts, can you simply index the eventually value of  
plays.count? You indexing process would have to contain more logic, but  
this logic is only executed once per document and not each time like it is  
during a query.

Can you provide some sample documents?

Cheers,

Ivan

On Fri, Oct 18, 2013 at 10:34 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> Hiya
> 
> Hello.
> 
> > I had the OOM problem and resolved by setting option  
> > 'index.cache.field.type: soft'.  
> > At now, my query and facet works file.
> > 
> > But I have faced new problem, pool performance.
> 
> That's what `soft` gives you 🙂 By using soft references, you haven't  
> solved the OOM problem, you've just forced ES to reload field data all the  
> time (which is very heavy).
> 
> You can set the indices.fielddata.cache.size size to avoid OOMs, but it's  
> a safety mechanism, not a solution. If you are running out of memory it'll  
> evict field data, which will affect performance. See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-fielddata.html)  
> You need more memory, or more nodes, or fewer facets. If you're faceting  
> on high cardinality string fields, that's going to use a lot of memory.
> 
> clint
> 
> --  
> 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:** ![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 21, 2013, 12:49pm UTC](https://discuss.elastic.co/t/how-to-improve-facet-performance/14006/4 "2013-10-21T12:49:33Z")

</div>

Thanks for kindly advice.

I have posted  
[Redirecting to Google Groups](https://groups.google.com/forum/#!topic/elasticsearch/Yt_US5NdiVQ).  
This page contains samples and specific queries.

Thanks again!

2013년 10월 19일 토요일 오전 3시 7분 3초 UTC+9, Ivan Brusic 님의 말:

> Instead of using scripts, can you simply index the eventually value of  
> plays.count? You indexing process would have to contain more logic, but  
> this logic is only executed once per document and not each time like it is  
> during a query.
> 
> Can you provide some sample documents?
> 
> Cheers,
> 
> Ivan
> 
> On Fri, Oct 18, 2013 at 10:34 AM, Clinton Gormley \<[cl...@traveljury.com](mailto:cl...@traveljury.com)\<javascript:\>
> 
> > wrote:
> 
> > Hiya
> > 
> > Hello.
> > 
> > > I had the OOM problem and resolved by setting option  
> > > 'index.cache.field.type: soft'.  
> > > At now, my query and facet works file.
> > > 
> > > But I have faced new problem, pool performance.
> > 
> > That's what `soft` gives you 🙂 By using soft references, you haven't  
> > solved the OOM problem, you've just forced ES to reload field data all the  
> > time (which is very heavy).
> > 
> > You can set the indices.fielddata.cache.size size to avoid OOMs, but it's  
> > a safety mechanism, not a solution. If you are running out of memory it'll  
> > evict field data, which will affect performance. See  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-fielddata.html)  
> > You need more memory, or more nodes, or fewer facets. If you're faceting  
> > on high cardinality string fields, that's going to use a lot of memory.
> > 
> > clint
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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/how-to-improve-facet-performance/14006/5 "2017-07-06T02:11:24Z")

</div>


