# Facets.total and hits.total dont match

**URL:** <https://discuss.elastic.co/t/facets-total-and-hits-total-dont-match/15335>\
**Category:** Elasticsearch\
**Created:** [January 21, 2014, 6:45am UTC](https://discuss.elastic.co/t/facets-total-and-hits-total-dont-match/15335 "2014-01-21T06:45:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)\
**Post date:** [January 21, 2014, 6:45am UTC](https://discuss.elastic.co/t/facets-total-and-hits-total-dont-match/15335/1 "2014-01-21T06:45:45Z")

</div>

I have an application where I need both search results and facet  
information. Everytime a query is framed based on some filter condition and  
query words and it is passed to both facet and search request as given  
below. The field (test\_field) on which the facet to be applied is present  
in all documents.

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();  
SearchRequestBuilder srb = client .prepareSearch("Test");  
srb.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery( boolQueryBuilder);  
and  
TermsFacetBuilder facBuilder = FacetBuilders.termsFacet("test\_field");  
facBuilder.facetFilter(FilterBuilders  
.queryFilter(boolQueryBuilder));  
facBuilder.fields("test\_field");  
facBuilder.global(true); // I tried commenting this too,  
but I get the same result  
srb.addFacet(facBuilder);

"hits" : {  
"total" : 117,  
"max\_score" : null,  
"hits" : [ {  
.... }]

"facets" : {  
"assettype" : {  
"\_type" : "terms",  
"missing" : 5,  
"total" : 119,  
"other" : 0,  
"terms" : [ {....  
}]

But the hit count is different from the facet count. Can anyone please  
explain me why this discrepancy?

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/b2ddb7fb-2b4f-488a-b944-0ac1d5342e39%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b2ddb7fb-2b4f-488a-b944-0ac1d5342e39%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)\
**Post date:** [January 21, 2014, 6:58am UTC](https://discuss.elastic.co/t/facets-total-and-hits-total-dont-match/15335/2 "2014-01-21T06:58:37Z")

</div>

I have indexed some records by making test\_field to be 'analyzed'. If the  
analyzed field causing this issue, is there any other facet type/work  
around which can solve the problem?

On Tuesday, January 21, 2014 12:15:45 PM UTC+5:30, Chetana wrote:

> I have an application where I need both search results and facet  
> information. Everytime a query is framed based on some filter condition and  
> query words and it is passed to both facet and search request as given  
> below. The field (test\_field) on which the facet to be applied is present  
> in all documents.
> 
> BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();  
> SearchRequestBuilder srb = client .prepareSearch("Test");
> 
> srb.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery( boolQueryBuilder);  
> and  
> TermsFacetBuilder facBuilder = FacetBuilders.termsFacet("test\_field");  
> facBuilder.facetFilter(FilterBuilders  
> .queryFilter(boolQueryBuilder));  
> facBuilder.fields("test\_field");  
> facBuilder.global(true); // I tried commenting this too,  
> but I get the same result  
> srb.addFacet(facBuilder);
> 
> "hits" : {  
> "total" : 117,  
> "max\_score" : null,  
> "hits" : [ {  
> .... }]
> 
> "facets" : {  
> "assettype" : {  
> "\_type" : "terms",  
> "missing" : 5,  
> "total" : 119,  
> "other" : 0,  
> "terms" : [ {....  
> }]
> 
> But the hit count is different from the facet count. Can anyone please  
> explain me why this discrepancy?
> 
> 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/a8ed55c0-6599-4612-995d-28d3340e69f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a8ed55c0-6599-4612-995d-28d3340e69f7%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Eric\_Rodriguez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_rodriguez/32/1281_2.png) [@Eric\_Rodriguez](https://discuss.elastic.co/u/Eric_Rodriguez)\
**Post date:** [January 21, 2014, 7:02am UTC](https://discuss.elastic.co/t/facets-total-and-hits-total-dont-match/15335/3 "2014-01-21T07:02:35Z")

</div>

Hi,

I don't have the link right now but IIRC when you have more than 1 shard there is no certainty about facet count accuracy...  
The best "workaround" is either 1 shard to get exact count or extend the number of results asked for facet to achieve better (still not exact) count.

Eric

Sent from my iPhone

> On 21 Jan 2014, at 07:58, Chetana [ambha.career@gmail.com](mailto:ambha.career@gmail.com) wrote:
> 
> I have indexed some records by making test\_field to be 'analyzed'. If the analyzed field causing this issue, is there any other facet type/work around which can solve the problem?
> 
> > On Tuesday, January 21, 2014 12:15:45 PM UTC+5:30, Chetana wrote:  
> > I have an application where I need both search results and facet information. Everytime a query is framed based on some filter condition and query words and it is passed to both facet and search request as given below. The field (test\_field) on which the facet to be applied is present in all documents.
> > 
> > BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();  
> > SearchRequestBuilder srb = client .prepareSearch("Test");  
> > srb.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery( boolQueryBuilder);  
> > and  
> > TermsFacetBuilder facBuilder = FacetBuilders.termsFacet("test\_field");  
> > facBuilder.facetFilter(FilterBuilders  
> > .queryFilter(boolQueryBuilder));  
> > facBuilder.fields("test\_field");  
> > facBuilder.global(true); // I tried commenting this too, but I get the same result  
> > srb.addFacet(facBuilder);
> > 
> > "hits" : {  
> > "total" : 117,  
> > "max\_score" : null,  
> > "hits" : [ {  
> > .... }]
> > 
> > "facets" : {  
> > "assettype" : {  
> > "\_type" : "terms",  
> > "missing" : 5,  
> > "total" : 119,  
> > "other" : 0,  
> > "terms" : [ {....  
> > }]
> > 
> > But the hit count is different from the facet count. Can anyone please explain me why this discrepancy?
> > 
> > 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/a8ed55c0-6599-4612-995d-28d3340e69f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a8ed55c0-6599-4612-995d-28d3340e69f7%40googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/E2A7D14B-CCA0-48D8-BB70-56FC0ACA3112%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/E2A7D14B-CCA0-48D8-BB70-56FC0ACA3112%40gmail.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, 1:55am UTC](https://discuss.elastic.co/t/facets-total-and-hits-total-dont-match/15335/4 "2017-07-06T01:55:45Z")

</div>


