# Bad performance for terms facet on no hits result

**URL:** https://discuss.elastic.co/t/bad-performance-for-terms-facet-on-no-hits-result/17739
**Category:** Elasticsearch
**Created:** [May 27, 2014, 6:12am UTC](https://discuss.elastic.co/t/bad-performance-for-terms-facet-on-no-hits-result/17739 "2014-05-27T06:12:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![deer](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@deer](https://discuss.elastic.co/u/deer)
#### Post date: [May 27, 2014, 6:12am UTC](https://discuss.elastic.co/t/bad-performance-for-terms-facet-on-no-hits-result/17739/1 "2014-05-27T06:12:00Z")

</div>

Hi All,

My elasticsearch version is 1.1.1. I have a 20 shards and 0 replica index  
having 4m docs.

It is fast (1ms) for my query.

{

- took: 1
- timed\_out: false
- \_shards: {
  - total: 20
  - successful: 20
  - failed: 0  
}

- hits: {
  - total: 0
  - max\_score: null
  - hits: []  
}

}

We do the query with terms facet on a high cardinality field 'a'. The query  
result is 0 hit and I assume it should be fast enough to calculate the  
terms facet(should be 0 term).

But when I fetching the terms from 0 hits, I got this  
{

- took: 46
- timed\_out: false
- \_shards: {
  - total: 20
  - successful: 20
  - failed: 0  
}

- hits: {
  - total: 0
  - max\_score: null
  - hits: []  
}

- facets: {
  - fc: a: {
    - \_type: terms
    - missing: 0
    - total: 0
    - other: 0
    - terms: []  
}  
}

}  
, which took much more than 1ms for the terms facet.

May I know is the terms facet not applied on the result hits only?

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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2531388f-674a-4a9f-8f93-e6bb57b2c593%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2531388f-674a-4a9f-8f93-e6bb57b2c593%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [May 27, 2014, 4:31pm UTC](https://discuss.elastic.co/t/bad-performance-for-terms-facet-on-no-hits-result/17739/2 "2014-05-27T16:31:26Z")

</div>

Is this a repeated test? There might be some cache loading going on during  
the first request. Values must be loaded into the cache before they can be  
filtered on. Try a repeated test.

--  
Ivan

On Mon, May 26, 2014 at 11:12 PM, Hui [dannyhui1103@gmail.com](mailto:dannyhui1103@gmail.com) wrote:

> Hi All,
> 
> My elasticsearch version is 1.1.1. I have a 20 shards and 0 replica index  
> having 4m docs.
> 
> It is fast (1ms) for my query.
> 
> {
> 
> - took: 1
> - timed\_out: false
> - \_shards: {
> - total: 20
> - successful: 20
> - failed: 0  
> }
> 
> - hits: {
> - total: 0
> - max\_score: null
> - hits:   
> }
> 
> }
> 
> We do the query with terms facet on a high cardinality field 'a'. The  
> query result is 0 hit and I assume it should be fast enough to calculate  
> the terms facet(should be 0 term).
> 
> But when I fetching the terms from 0 hits, I got this  
> {
> 
> - took: 46
> - timed\_out: false
> - \_shards: {
> - total: 20
> - successful: 20
> - failed: 0  
> }
> 
> - hits: {
> - total: 0
> - max\_score: null
> - hits:   
> }
> 
> - facets: {
> - fc: a: {
> - \_type: terms
> - missing: 0
> - total: 0
> - other: 0
> - terms:   
> }  
> }
> 
> }  
> , which took much more than 1ms for the terms facet.
> 
> May I know is the terms facet not applied on the result hits only?
> 
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/2531388f-674a-4a9f-8f93-e6bb57b2c593%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2531388f-674a-4a9f-8f93-e6bb57b2c593%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/2531388f-674a-4a9f-8f93-e6bb57b2c593%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2531388f-674a-4a9f-8f93-e6bb57b2c593%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDuP-KGPbr5FiCf8C2V%2B%2BgG4EUjesMD%3Dvk1K0MZookEMQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDuP-KGPbr5FiCf8C2V%2B%2BgG4EUjesMD%3Dvk1K0MZookEMQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:26am UTC](https://discuss.elastic.co/t/bad-performance-for-terms-facet-on-no-hits-result/17739/3 "2017-07-06T01:26:38Z")

</div>


