# \_count vs. filter facet

**URL:** <https://discuss.elastic.co/t/-count-vs-filter-facet/11846>\
**Category:** Elasticsearch\
**Created:** [May 7, 2013, 7:32am UTC](https://discuss.elastic.co/t/-count-vs-filter-facet/11846 "2013-05-07T07:32:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Kinsalb](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Chris\_Kinsalb](https://discuss.elastic.co/u/Chris_Kinsalb)\
**Post date:** [May 7, 2013, 7:32am UTC](https://discuss.elastic.co/t/-count-vs-filter-facet/11846/1 "2013-05-07T07:32:38Z")

</div>

Hello Group,

Could someone please explain to me the difference between the  
\*  
\_count interface \*vs.the _filter facet_

From the elasticsearch documentation:

Filter facet:  
"A filter facet (not to be confused with a facet filter) allows you to  
return a count of the hits matching the filter."

Count API:  
"The count API allows to easily execute a query and get the number of  
matches for that query"

Essentially, would I get the same results for a given query, i.e. a count  
of matching documents?

If not, what is the actual difference (operation-wise and results).

Thank you!

--  
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:** ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)\
**Post date:** [May 15, 2013, 3:27pm UTC](https://discuss.elastic.co/t/-count-vs-filter-facet/11846/2 "2013-05-15T15:27:34Z")

</div>

Hi Chris,

These two different beasts.

A \_count allows to quickly get the number of documents matching a single  
but arbitrary query. Important to note here that queries are not the same  
as filters. Filters are similar in nature to queries but do not involve  
scoring and sorting and thus are limited in functionality but tend to be  
faster.

A fiter facet indeed gives a count of document matching a filter but  
because it is a facet (rather than an endpoint like \_count) it is a  
completely different type of a lego block. It is a part of a search request  
and the number it gives the number of document that match the filter _AND_  
the documents that match the query of the search. Because it is a part of a  
search request, you can have multiple (filter) facet in one request. Using  
multiple facets gives a counting analysis for multiple subsets the results.  
This is especially more efficient if the main query is heavy and the  
filters you use in the facets are cached.

Hope this clarifies things a bit.

Boaz

On Tuesday, May 7, 2013 9:32:38 AM UTC+2, Chris Kinsalb wrote:

> Hello Group,
> 
> Could someone please explain to me the difference between the  
> \*  
> \_count interface \*vs.the _filter facet_
> 
> From the elasticsearch documentation:
> 
> Filter facet:  
> "A filter facet (not to be confused with a facet filter) allows you to  
> return a count of the hits matching the filter."
> 
> Count API:  
> "The count API allows to easily execute a query and get the number of  
> matches for that query"
> 
> Essentially, would I get the same results for a given query, i.e. a count  
> of matching documents?
> 
> If not, what is the actual difference (operation-wise and results).
> 
> Thank you!

--  
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:** ![Chris\_Kinsalb](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Chris\_Kinsalb](https://discuss.elastic.co/u/Chris_Kinsalb)\
**Post date:** [May 21, 2013, 1:43pm UTC](https://discuss.elastic.co/t/-count-vs-filter-facet/11846/3 "2013-05-21T13:43:00Z")

</div>

Hello Boaz,

thanks for the clarification!

On Wednesday, May 15, 2013 5:27:34 PM UTC+2, Boaz Leskes wrote:

> Hi Chris,
> 
> These two different beasts.
> 
> A \_count allows to quickly get the number of documents matching a single  
> but arbitrary query. Important to note here that queries are not the same  
> as filters. Filters are similar in nature to queries but do not involve  
> scoring and sorting and thus are limited in functionality but tend to be  
> faster.
> 
> A fiter facet indeed gives a count of document matching a filter but  
> because it is a facet (rather than an endpoint like \_count) it is a  
> completely different type of a lego block. It is a part of a search request  
> and the number it gives the number of document that match the filter _AND_  
> the documents that match the query of the search. Because it is a part of a  
> search request, you can have multiple (filter) facet in one request. Using  
> multiple facets gives a counting analysis for multiple subsets the results.  
> This is especially more efficient if the main query is heavy and the  
> filters you use in the facets are cached.
> 
> Hope this clarifies things a bit.
> 
> Boaz
> 
> On Tuesday, May 7, 2013 9:32:38 AM UTC+2, Chris Kinsalb wrote:
> 
> > Hello Group,
> > 
> > Could someone please explain to me the difference between the  
> > \*  
> > \_count interface \*vs.the _filter facet_
> > 
> > From the elasticsearch documentation:
> > 
> > Filter facet:  
> > "A filter facet (not to be confused with a facet filter) allows you to  
> > return a count of the hits matching the filter."
> > 
> > Count API:  
> > "The count API allows to easily execute a query and get the number of  
> > matches for that query"
> > 
> > Essentially, would I get the same results for a given query, i.e. a count  
> > of matching documents?
> > 
> > If not, what is the actual difference (operation-wise and results).
> > 
> > Thank you!

--  
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:35am UTC](https://discuss.elastic.co/t/-count-vs-filter-facet/11846/4 "2017-07-06T02:35:31Z")

</div>


