# Facets using field or script\_field?

**URL:** <https://discuss.elastic.co/t/facets-using-field-or-script-field/13750>\
**Category:** Elasticsearch\
**Created:** [September 25, 2013, 2:47pm UTC](https://discuss.elastic.co/t/facets-using-field-or-script-field/13750 "2013-09-25T14:47:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillermo\_Arias\_del\_](https://avatars.discourse-cdn.com/v4/letter/g/cab0a1/32.png) [@Guillermo\_Arias\_del\_](https://discuss.elastic.co/u/Guillermo_Arias_del_)\
**Post date:** [September 25, 2013, 2:47pm UTC](https://discuss.elastic.co/t/facets-using-field-or-script-field/13750/1 "2013-09-25T14:47:02Z")

</div>

Hello,

I am trying to improve the performance of my faceted search requests and I  
found something interesting: for the tests I was doing, changing the facet  
term from:

"field": ""

to

"script\_field": "doc[''].value"

made my query 8x faster. Later, in some tests, it reached 42x!. I didn't  
understand it, but I was happy...  
... and then, testing a particularly heavy query (the top facet has a count  
of 995869), it went the other way round: the query was 2x slower.

So my question is: what is the difference? what should I use?

I've read that Elasticsearch loads all facets, so I tried preventing this  
by copying the main query in a facet filter ("facet\_filter": { "query":  
\<main\_query\> }), but it just gets worse.

The facet field is stored and my HQ plugin says there have been 0 field  
evictions in a field cache of 488.7 mb.

Thanks.

--  
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:14am UTC](https://discuss.elastic.co/t/facets-using-field-or-script-field/13750/2 "2017-07-06T02:14:44Z")

</div>


