# Facets only when number of hits is on given range

**URL:** <https://discuss.elastic.co/t/facets-only-when-number-of-hits-is-on-given-range/3576>\
**Category:** Elasticsearch\
**Created:** [November 16, 2010, 9:50am UTC](https://discuss.elastic.co/t/facets-only-when-number-of-hits-is-on-given-range/3576 "2010-11-16T09:50:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ludovic\_Levesque](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ludovic_levesque/32/3031_2.png) [@Ludovic\_Levesque](https://discuss.elastic.co/u/Ludovic_Levesque)\
**Post date:** [November 16, 2010, 9:50am UTC](https://discuss.elastic.co/t/facets-only-when-number-of-hits-is-on-given-range/3576/1 "2010-11-16T09:50:35Z")

</div>

Hi Shay,

I don't know how faceting works internally, but will it be possible to  
gather facets only when number of hits is less than a given threshold  
?

Something like this for example:

"facets": {  
"facet1": {  
"terms": {  
"field": "field1",  
"size": 100  
},  
"only\_when": {  
"hits": {"lte": 10000}  
}  
},  
"facet2": {  
"terms": {  
"field": "field2",  
"size": 10  
}  
}  
}

Because on some fields, computing facets introduces a little overhead  
even if we don't want the final results because it's not appropriate  
when we have many hits.

We can do this in the application, but if we can avoid some roundtrips  
to the cluster, it will be great.

Another idea but maybe more difficult to implement: to be able to  
gather some facets on some fields only when number of different terms  
of another field is less than a given number:  
facets on subcategories only when number of different topcategories  
are less than 5 for example or facets on prices only if we have only  
one category of products, etc...

Regards,  
Ludo

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 17, 2010, 10:08am UTC](https://discuss.elastic.co/t/facets-only-when-number-of-hits-is-on-given-range/3576/2 "2010-11-17T10:08:37Z")

</div>

The way facets are implemented today is that they are aggregated as part of  
the search process, which makes them really fast with low overhead, but does  
mean that you can't use data that is only available post search (like the  
number of hits).

-shay.banon

On Tue, Nov 16, 2010 at 11:50 AM, Ludovic Levesque [luddic@gmail.com](mailto:luddic@gmail.com) wrote:

> Hi Shay,
> 
> I don't know how faceting works internally, but will it be possible to  
> gather facets only when number of hits is less than a given threshold  
> ?
> 
> Something like this for example:
> 
> "facets": {  
> "facet1": {  
> "terms": {  
> "field": "field1",  
> "size": 100  
> },  
> "only\_when": {  
> "hits": {"lte": 10000}  
> }  
> },  
> "facet2": {  
> "terms": {  
> "field": "field2",  
> "size": 10  
> }  
> }  
> }
> 
> Because on some fields, computing facets introduces a little overhead  
> even if we don't want the final results because it's not appropriate  
> when we have many hits.
> 
> We can do this in the application, but if we can avoid some roundtrips  
> to the cluster, it will be great.
> 
> Another idea but maybe more difficult to implement: to be able to  
> gather some facets on some fields only when number of different terms  
> of another field is less than a given number:  
> facets on subcategories only when number of different topcategories  
> are less than 5 for example or facets on prices only if we have only  
> one category of products, etc...
> 
> Regards,  
> Ludo

---

<div class="post-metadata">

**Author:** ![Ludovic\_Levesque](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ludovic_levesque/32/3031_2.png) [@Ludovic\_Levesque](https://discuss.elastic.co/u/Ludovic_Levesque)\
**Post date:** [November 17, 2010, 12:55pm UTC](https://discuss.elastic.co/t/facets-only-when-number-of-hits-is-on-given-range/3576/3 "2010-11-17T12:55:00Z")

</div>

Ok, so better to do one more roundtrip if really needed

Thanks again

On Wed, Nov 17, 2010 at 11:08 AM, Shay Banon  
[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> The way facets are implemented today is that they are aggregated as part of  
> the search process, which makes them really fast with low overhead, but does  
> mean that you can't use data that is only available post search (like the  
> number of hits).  
> -shay.banon
> 
> On Tue, Nov 16, 2010 at 11:50 AM, Ludovic Levesque [luddic@gmail.com](mailto:luddic@gmail.com) wrote:
> 
> > Hi Shay,
> > 
> > I don't know how faceting works internally, but will it be possible to  
> > gather facets only when number of hits is less than a given threshold  
> > ?
> > 
> > Something like this for example:
> > 
> > "facets": {  
> > "facet1": {  
> > "terms": {  
> > "field": "field1",  
> > "size": 100  
> > },  
> > "only\_when": {  
> > "hits": {"lte": 10000}  
> > }  
> > },  
> > "facet2": {  
> > "terms": {  
> > "field": "field2",  
> > "size": 10  
> > }  
> > }  
> > }
> > 
> > Because on some fields, computing facets introduces a little overhead  
> > even if we don't want the final results because it's not appropriate  
> > when we have many hits.
> > 
> > We can do this in the application, but if we can avoid some roundtrips  
> > to the cluster, it will be great.
> > 
> > Another idea but maybe more difficult to implement: to be able to  
> > gather some facets on some fields only when number of different terms  
> > of another field is less than a given number:  
> > facets on subcategories only when number of different topcategories  
> > are less than 5 for example or facets on prices only if we have only  
> > one category of products, etc...
> > 
> > Regards,  
> > Ludo

---

<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, 4:16am UTC](https://discuss.elastic.co/t/facets-only-when-number-of-hits-is-on-given-range/3576/4 "2017-07-06T04:16:21Z")

</div>


