# SearchResponse hits vs facet counts

**URL:** <https://discuss.elastic.co/t/searchresponse-hits-vs-facet-counts/8934>\
**Category:** Elasticsearch\
**Created:** [September 5, 2012, 2:06pm UTC](https://discuss.elastic.co/t/searchresponse-hits-vs-facet-counts/8934 "2012-09-05T14:06:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deejay](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@deejay](https://discuss.elastic.co/u/deejay)\
**Post date:** [September 5, 2012, 2:06pm UTC](https://discuss.elastic.co/t/searchresponse-hits-vs-facet-counts/8934/1 "2012-09-05T14:06:43Z")

</div>

Hi,

Is there a reason why I cannot use the SearchResponse.hits().totalHits() number instead of having a facet in the same query that returns the same number?

For example, do I need the facet in the query below or can I not just use the totalHits() count instead as both return the same number?

{"query": {  
"filtered" : {  
"filter" : {  
"term" : { "myField" : "myValue" }  
},  
"query" : { "match\_all" : {} }  
}  
},  
"facets" : {  
"my\_facet" : {  
"filter" : {  
"term" : { "myField" : "myValue" }  
}  
}  
},  
"from":0,  
"size":20  
}'

Kind Regards,

Dirk

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 7, 2012, 9:37am UTC](https://discuss.elastic.co/t/searchresponse-hits-vs-facet-counts/8934/2 "2012-09-07T09:37:29Z")

</div>

If you need only to know the number total of hits, don't use facets.  
SearchResponse.hits().totalHits() will do it.

David.

Le 5 septembre 2012 à 16:06, Dirk [dirk.deejay@gmail.com](mailto:dirk.deejay@gmail.com) a écrit :

> Hi,
> 
> Is there a reason why I cannot use the SearchResponse.hits().totalHits()  
> number instead of having a facet in the same query that returns the same  
> number?
> 
> For example, do I need the facet in the query below or can I not just use  
> the totalHits() count instead as both return the same number?
> 
> {"query": {  
> "filtered" : {  
> "filter" : {  
> "term" : { "myField" : "myValue" }  
> },  
> "query" : { "match\_all" : {} }  
> }  
> },  
> "facets" : {  
> "my\_facet" : {  
> "filter" : {  
> "term" : { "myField" : "myValue" }  
> }  
> }  
> },  
> "from":0,  
> "size":20  
> }'
> 
> Kind Regards,
> 
> Dirk
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/SearchResponse-hits-vs-facet-counts-tp4022436.html](http://elasticsearch-users.115913.n3.nabble.com/SearchResponse-hits-vs-facet-counts-tp4022436.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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, 3:13am UTC](https://discuss.elastic.co/t/searchresponse-hits-vs-facet-counts/8934/3 "2017-07-06T03:13:49Z")

</div>


