# Facet count - strange behaviour - different result for different size of most frequent terms

**URL:** https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064
**Category:** Elasticsearch
**Created:** [March 7, 2013, 7:16pm UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064 "2013-03-07T19:16:47Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Artur\_Konczak](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@Artur\_Konczak](https://discuss.elastic.co/u/Artur_Konczak)
#### Post date: [March 7, 2013, 7:16pm UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/1 "2013-03-07T19:16:47Z")

</div>

I'm looking for any good explanation for a different value for facet count.  
I have changed only the return size of the most frequent terms.

My ES is in version 0.20.5.

_The query looks like this:_

{  
"size": 0,  
"query": {  
"field": {  
"\_all": "\*"  
}  
},  
"facets": {  
"publisher1": {  
"terms": {  
"field": "publisher.untouched",  
"size": 1  
}  
},  
"publisher2": {  
"terms": {  
"field": "publisher.untouched",  
"size": 2  
}  
},  
"publisher3": {  
"terms": {  
"field": "publisher.untouched",  
"size": 3  
}  
},  
"publisher4": {  
"terms": {  
"field": "publisher.untouched",  
"size": 4  
}  
},  
"publisher10": {  
"terms": {  
"field": "publisher.untouched",  
"size": 10  
}  
}  
}  
}

_And the answer is:_  
{  
"took" : 6,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 319,  
"max\_score" : 1.0,  
"hits" : []  
},  
"facets" : {  
"publisher1" : {  
"\_type" : "terms",  
"missing" : 289,  
"total" : 30,  
"other" : 13,  
"terms" : [ {  
"term" : "ABC",  
"count" : 17  
} ]  
},  
"publisher2" : {  
"\_type" : "terms",  
"missing" : 289,  
"total" : 30,  
"other" : 11,  
"terms" : [ {  
"term" : "ABC",  
"count" : 17  
}, {  
"term" : "publisher",  
"count" : 2  
} ]  
},  
"publisher3" : {  
"\_type" : "terms",  
"missing" : 289,  
"total" : 30,  
"other" : 8,  
"terms" : [ {  
"term" : "ABC",  
"count" : 18  
}, {  
"term" : "publisher",  
"count" : 2  
}, {  
"term" : "DEF",  
"count" : 2  
} ]  
},  
"publisher4" : {  
"\_type" : "terms",  
"missing" : 289,  
"total" : 30,  
"other" : 6,  
"terms" : [ {  
"term" : "ABC",  
"count" : 18  
}, {  
"term" : "publisher",  
"count" : 2  
}, {  
"term" : "DEF",  
"count" : 2  
}, {  
"term" : "ABC1",  
"count" : 2  
} ]  
},  
"publisher10" : {  
"\_type" : "terms",  
"missing" : 289,  
"total" : 30,  
"other" : 0,  
"terms" : [ {  
"term" : "ABC",  
"count" : 18  
}, {  
"term" : "publisher",  
"count" : 2  
}, {  
"term" : "DEF",  
"count" : 2  
}, {  
"term" : "ABC1",  
"count" : 2  
}, {  
"term" : "test1",  
"count" : 1  
}, {  
"term" : "self",  
"count" : 1  
}, {  
"term" : "eva3",  
"count" : 1  
}, {  
"term" : "claire",  
"count" : 1  
}, {  
"term" : "ABC2",  
"count" : 1  
}, {  
"term" : "asdfa",  
"count" : 1  
} ]  
}  
}  
}

--  
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: ![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: [March 7, 2013, 7:33pm UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/2 "2013-03-07T19:33:04Z")

</div>

You have probably more than one shard, don't you?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 mars 2013 à 20:16, Artur Konczak [akonczak@gmail.com](mailto:akonczak@gmail.com) a écrit :

> I'm looking for any good explanation for a different value for facet count.  
> I have changed only the return size of the most frequent terms.
> 
> My ES is in version 0.20.5.
> 
> The query looks like this:
> 
> {  
> "size": 0,  
> "query": {  
> "field": {  
> "\_all": "\*"  
> }  
> },  
> "facets": {  
> "publisher1": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 1  
> }  
> },  
> "publisher2": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 2  
> }  
> },  
> "publisher3": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 3  
> }  
> },  
> "publisher4": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 4  
> }  
> },  
> "publisher10": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 10  
> }  
> }  
> }  
> }
> 
> And the answer is:  
> {  
> "took" : 6,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 319,  
> "max\_score" : 1.0,  
> "hits" :   
> },  
> "facets" : {  
> "publisher1" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 13,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 17  
> } ]  
> },  
> "publisher2" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 11,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 17  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> } ]  
> },  
> "publisher3" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 8,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> } ]  
> },  
> "publisher4" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 6,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> }, {  
> "term" : "ABC1",  
> "count" : 2  
> } ]  
> },  
> "publisher10" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 0,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> }, {  
> "term" : "ABC1",  
> "count" : 2  
> }, {  
> "term" : "test1",  
> "count" : 1  
> }, {  
> "term" : "self",  
> "count" : 1  
> }, {  
> "term" : "eva3",  
> "count" : 1  
> }, {  
> "term" : "claire",  
> "count" : 1  
> }, {  
> "term" : "ABC2",  
> "count" : 1  
> }, {  
> "term" : "asdfa",  
> "count" : 1  
> } ]  
> }  
> }  
> }
> 
> --  
> 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).

--  
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: ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)
#### Post date: [March 7, 2013, 10:48pm UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/3 "2013-03-07T22:48:21Z")

</div>

David,

Could you elaborate how having multiple shard can affect facet counts?

Thank you,  
Alex

On Thursday, March 7, 2013 2:33:04 PM UTC-5, David Pilato wrote:

> You have probably more than one shard, don't you?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 7 mars 2013 à 20:16, Artur Konczak \<[akon...@gmail.com](mailto:akon...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> I'm looking for any good explanation for a different value for facet  
> count.  
> I have changed only the return size of the most frequent terms.
> 
> My ES is in version 0.20.5.
> 
> _The query looks like this:_
> 
> {  
> "size": 0,  
> "query": {  
> "field": {  
> "\_all": "\*"  
> }  
> },  
> "facets": {  
> "publisher1": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 1  
> }  
> },  
> "publisher2": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 2  
> }  
> },  
> "publisher3": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 3  
> }  
> },  
> "publisher4": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 4  
> }  
> },  
> "publisher10": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 10  
> }  
> }  
> }  
> }
> 
> _And the answer is:_  
> {  
> "took" : 6,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 319,  
> "max\_score" : 1.0,  
> "hits" :   
> },  
> "facets" : {  
> "publisher1" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 13,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 17  
> } ]  
> },  
> "publisher2" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 11,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 17  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> } ]  
> },  
> "publisher3" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 8,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> } ]  
> },  
> "publisher4" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 6,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> }, {  
> "term" : "ABC1",  
> "count" : 2  
> } ]  
> },  
> "publisher10" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 0,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> }, {  
> "term" : "ABC1",  
> "count" : 2  
> }, {  
> "term" : "test1",  
> "count" : 1  
> }, {  
> "term" : "self",  
> "count" : 1  
> }, {  
> "term" : "eva3",  
> "count" : 1  
> }, {  
> "term" : "claire",  
> "count" : 1  
> }, {  
> "term" : "ABC2",  
> "count" : 1  
> }, {  
> "term" : "asdfa",  
> "count" : 1  
> } ]  
> }  
> }  
> }
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [March 8, 2013, 3:16am UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/4 "2013-03-08T03:16:58Z")

</div>

So you have more than one shard 😉

Facets are computed per shard. Then results are _merged_.  
If you are _unlucky_, a value that is in the TOP5 in shard 1 is only on position #6 in shard 2.  
So when you ask for a TOP5 facet, these ones won't be _merged_.

See also: [Inconsistent facet counts · Issue #1832 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1832)  
And [terms facet gives wrong count with n\_shards \> 1 · Issue #1305 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1305)

## HTH

David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 mars 2013 à 23:48, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) a écrit :

David,

Could you elaborate how having multiple shard can affect facet counts?

Thank you,  
Alex

On Thursday, March 7, 2013 2:33:04 PM UTC-5, David Pilato wrote:

> You have probably more than one shard, don't you?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 7 mars 2013 à 20:16, Artur Konczak [akon...@gmail.com](mailto:akon...@gmail.com) a écrit :
> 
> > I'm looking for any good explanation for a different value for facet count.  
> > I have changed only the return size of the most frequent terms.
> > 
> > My ES is in version 0.20.5.
> > 
> > The query looks like this:
> > 
> > {  
> > "size": 0,  
> > "query": {  
> > "field": {  
> > "\_all": "\*"  
> > }  
> > },  
> > "facets": {  
> > "publisher1": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 1  
> > }  
> > },  
> > "publisher2": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 2  
> > }  
> > },  
> > "publisher3": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 3  
> > }  
> > },  
> > "publisher4": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 4  
> > }  
> > },  
> > "publisher10": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 10  
> > }  
> > }  
> > }  
> > }
> > 
> > And the answer is:  
> > {  
> > "took" : 6,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 319,  
> > "max\_score" : 1.0,  
> > "hits" :   
> > },  
> > "facets" : {  
> > "publisher1" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 13,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 17  
> > } ]  
> > },  
> > "publisher2" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 11,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 17  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher3" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 8,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher4" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 6,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > }, {  
> > "term" : "ABC1",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher10" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > }, {  
> > "term" : "ABC1",  
> > "count" : 2  
> > }, {  
> > "term" : "test1",  
> > "count" : 1  
> > }, {  
> > "term" : "self",  
> > "count" : 1  
> > }, {  
> > "term" : "eva3",  
> > "count" : 1  
> > }, {  
> > "term" : "claire",  
> > "count" : 1  
> > }, {  
> > "term" : "ABC2",  
> > "count" : 1  
> > }, {  
> > "term" : "asdfa",  
> > "count" : 1  
> > } ]  
> > }  
> > }  
> > }
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.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).  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)
#### Post date: [March 8, 2013, 3:59am UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/5 "2013-03-08T03:59:41Z")

</div>

Darn darn darn!!

Thanks for the pointer David. Do you ever sleep? You seem to have been answering question for straight 24 hours 🙂

I should have known better and evaluated/developed with multiple shards then I would have known of it. But I had just 70k docs so I did not want to skew my searches.

The app is heavily dependent on counts and summs and everything gets rolled up so any deviation will be very visible

Need to check how it affects other and missing counts if at all

--  
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: ![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: [March 8, 2013, 7:21am UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/6 "2013-03-08T07:21:45Z")

</div>

Haha! Sometimes I wake up during the night (insomnia ?) and I look at the ML and... 😉

There are some way to get right numbers:

- index with 1 shard
- use routing and when doing search use this routing option. But it means that you can group documents by something. For example, if in your use case, you have a username and the user can only search on its docs, use routing=username. Documents will go to the same shard. So facets will have all needed documents.
- increase the number of buckets. If you need a TOP5, ask for a TOP20 for example. You will have more chance to have the good answer.

That said, I would love to have an option that allows to do another round trip on shards that did not gives any values for the current TOPx merged values to have a chance to correct numbers.  
There is a cost, but if the user really need absolute values (not a percentage), I think he will accept to pay the price. -\> this is the suggestion in the issues BTW.

HTH  
(Time for a real wake up and coffee 😉 )

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 8 mars 2013 à 04:59, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) a écrit :

Darn darn darn!!

Thanks for the pointer David. Do you ever sleep? You seem to have been answering question for straight 24 hours 🙂

I should have known better and evaluated/developed with multiple shards then I would have known of it. But I had just 70k docs so I did not want to skew my searches.

The app is heavily dependent on counts and summs and everything gets rolled up so any deviation will be very visible

Need to check how it affects other and missing counts if at all

--  
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).

--  
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: ![Artur\_Konczak](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@Artur\_Konczak](https://discuss.elastic.co/u/Artur_Konczak)
#### Post date: [March 8, 2013, 8:54am UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/7 "2013-03-08T08:54:13Z")

</div>

Yes, I have 5 shards, I should look harder for an answer on the group  
before I post new query.  
The best explanation for my problem is here:

> <https://github.com/elastic/elasticsearch/issues/1305>
>
> I'm working with nested documents and have noticed that my faceted search interf…ace is giving the wrong counts when I have more than one shard. To be more specific, I'm working with RDF triples (entity \> attribute \> value) and I'm nesting the attributes (called predicates in my example):
> 
> \`\`\`
> {
> "\_id" : "512a2c022f0b4e3daa341e6c8bcf6c2f",
> "url": "http://dbpedia.org/resource/Alan\_Shepard",
> "predicates": \[
> {
> "type": "type",
> "string\_value": \["thing", "person", "astronaut"\]
> }, {
> "type": "label",
> "string\_value": \["Alan Shepard"\]
> }, {
> "type": "time in space",
> "float\_value": \[216.950\]
> },
> ... lots more
> \]
> }
> \`\`\`
> 
> I've created a shell script (https://gist.github.com/1196986) that recreates the problem with a fresh index. The created data set has these totals:
> \- thing (30)
> \- creative work (20)
> \- video game (10)
> \- tv show (10)
> \- people (10)
> 
> With only \*\*one shard\*\* the following query gives the correct counts no matter what the size parameter is set to:
> 
> \`\`\`
> {
> "size": 0,
> "query": {
> "match\_all": {}
> },
> "facets": {
> "type\_counts": {
> "terms": {
> "field": "string\_value",
> "size": 5
> },
> "nested": "predicates",
> "facet\_filter": {
> "term": {
> "type": "type"
> }
> }
> }
> }
> }
> \`\`\`
> 
> However, with \*\*more than one shard\*\* the size parameter affects the accuracy of the counts. If it is equal to or greater than the number of terms returned by the facet query (5 in this case) then it works fine. However, the terms at the bottom of the list start to display low counts as you reduce the size parameter:
> 
> With "size" : 4
> \- thing (30)
> \- creative work (20)
> \- video game (10)
> \- \*\*tv show (9)\*\*
> 
> With "size" : 3
> \- thing (30)
> \- \*\*creative work (15)\*\*
> \- \*\*video game (9)\*\*
> 
> With "size" : 2
> \- thing (30)
> \- \*\*creative work (15)\*\*
> 
> So it looks like the sub-totals from some of the shards aren't being included for some reason. BTW I'm on ubuntu and the problem seems to affect all versions of ES I've tried (17.0, 17.1 and 17.6). Any ideas...?
> 
> P.S. absolutely loving ES - it's made my life a lot easier :)

Thank you David.

On Thursday, 7 March 2013 19:33:04 UTC, David Pilato wrote:

> You have probably more than one shard, don't you?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 7 mars 2013 à 20:16, Artur Konczak \<[akon...@gmail.com](mailto:akon...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> I'm looking for any good explanation for a different value for facet  
> count.  
> I have changed only the return size of the most frequent terms.
> 
> My ES is in version 0.20.5.
> 
> _The query looks like this:_
> 
> {  
> "size": 0,  
> "query": {  
> "field": {  
> "\_all": "\*"  
> }  
> },  
> "facets": {  
> "publisher1": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 1  
> }  
> },  
> "publisher2": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 2  
> }  
> },  
> "publisher3": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 3  
> }  
> },  
> "publisher4": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 4  
> }  
> },  
> "publisher10": {  
> "terms": {  
> "field": "publisher.untouched",  
> "size": 10  
> }  
> }  
> }  
> }
> 
> _And the answer is:_  
> {  
> "took" : 6,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 319,  
> "max\_score" : 1.0,  
> "hits" :   
> },  
> "facets" : {  
> "publisher1" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 13,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 17  
> } ]  
> },  
> "publisher2" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 11,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 17  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> } ]  
> },  
> "publisher3" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 8,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> } ]  
> },  
> "publisher4" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 6,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> }, {  
> "term" : "ABC1",  
> "count" : 2  
> } ]  
> },  
> "publisher10" : {  
> "\_type" : "terms",  
> "missing" : 289,  
> "total" : 30,  
> "other" : 0,  
> "terms" : [ {  
> "term" : "ABC",  
> "count" : 18  
> }, {  
> "term" : "publisher",  
> "count" : 2  
> }, {  
> "term" : "DEF",  
> "count" : 2  
> }, {  
> "term" : "ABC1",  
> "count" : 2  
> }, {  
> "term" : "test1",  
> "count" : 1  
> }, {  
> "term" : "self",  
> "count" : 1  
> }, {  
> "term" : "eva3",  
> "count" : 1  
> }, {  
> "term" : "claire",  
> "count" : 1  
> }, {  
> "term" : "ABC2",  
> "count" : 1  
> }, {  
> "term" : "asdfa",  
> "count" : 1  
> } ]  
> }  
> }  
> }
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [March 8, 2013, 8:55am UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/8 "2013-03-08T08:55:27Z")

</div>

No problem.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 8 mars 2013 à 09:54, Artur Konczak [akonczak@gmail.com](mailto:akonczak@gmail.com) a écrit :

> Yes, I have 5 shards, I should look harder for an answer on the group before I post new query.  
> The best explanation for my problem is here:  
> [https://github.com/elasticsearch/elasticsearch/issues/1305](https://github.com/elasticsearch/elasticsearch/issues/1305)
> 
> Thank you David.
> 
> On Thursday, 7 March 2013 19:33:04 UTC, David Pilato wrote:  
> You have probably more than one shard, don't you?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 7 mars 2013 à 20:16, Artur Konczak [akon...@gmail.com](mailto:akon...@gmail.com) a écrit :
> 
> > I'm looking for any good explanation for a different value for facet count.  
> > I have changed only the return size of the most frequent terms.
> > 
> > My ES is in version 0.20.5.
> > 
> > The query looks like this:
> > 
> > {  
> > "size": 0,  
> > "query": {  
> > "field": {  
> > "\_all": "\*"  
> > }  
> > },  
> > "facets": {  
> > "publisher1": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 1  
> > }  
> > },  
> > "publisher2": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 2  
> > }  
> > },  
> > "publisher3": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 3  
> > }  
> > },  
> > "publisher4": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 4  
> > }  
> > },  
> > "publisher10": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 10  
> > }  
> > }  
> > }  
> > }
> > 
> > And the answer is:  
> > {  
> > "took" : 6,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 319,  
> > "max\_score" : 1.0,  
> > "hits" :   
> > },  
> > "facets" : {  
> > "publisher1" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 13,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 17  
> > } ]  
> > },  
> > "publisher2" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 11,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 17  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher3" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 8,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher4" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 6,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > }, {  
> > "term" : "ABC1",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher10" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > }, {  
> > "term" : "ABC1",  
> > "count" : 2  
> > }, {  
> > "term" : "test1",  
> > "count" : 1  
> > }, {  
> > "term" : "self",  
> > "count" : 1  
> > }, {  
> > "term" : "eva3",  
> > "count" : 1  
> > }, {  
> > "term" : "claire",  
> > "count" : 1  
> > }, {  
> > "term" : "ABC2",  
> > "count" : 1  
> > }, {  
> > "term" : "asdfa",  
> > "count" : 1  
> > } ]  
> > }  
> > }  
> > }
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![smhdiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smhdiu/32/1808_2.png) [@smhdiu](https://discuss.elastic.co/u/smhdiu)
#### Post date: [March 8, 2013, 10:14am UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/9 "2013-03-08T10:14:03Z")

</div>

Thanks David 🙂

On Friday, 8 March 2013 08:54:13 UTC, Artur Konczak wrote:

> Yes, I have 5 shards, I should look harder for an answer on the group  
> before I post new query.  
> The best explanation for my problem is here:  
> [https://github.com/elasticsearch/elasticsearch/issues/1305](https://github.com/elasticsearch/elasticsearch/issues/1305)
> 
> Thank you David.
> 
> On Thursday, 7 March 2013 19:33:04 UTC, David Pilato wrote:
> 
> > You have probably more than one shard, don't you?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 7 mars 2013 à 20:16, Artur Konczak [akon...@gmail.com](mailto:akon...@gmail.com) a écrit :
> > 
> > I'm looking for any good explanation for a different value for facet  
> > count.  
> > I have changed only the return size of the most frequent terms.
> > 
> > My ES is in version 0.20.5.
> > 
> > _The query looks like this:_
> > 
> > {  
> > "size": 0,  
> > "query": {  
> > "field": {  
> > "\_all": "\*"  
> > }  
> > },  
> > "facets": {  
> > "publisher1": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 1  
> > }  
> > },  
> > "publisher2": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 2  
> > }  
> > },  
> > "publisher3": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 3  
> > }  
> > },  
> > "publisher4": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 4  
> > }  
> > },  
> > "publisher10": {  
> > "terms": {  
> > "field": "publisher.untouched",  
> > "size": 10  
> > }  
> > }  
> > }  
> > }
> > 
> > _And the answer is:_  
> > {  
> > "took" : 6,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 319,  
> > "max\_score" : 1.0,  
> > "hits" :   
> > },  
> > "facets" : {  
> > "publisher1" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 13,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 17  
> > } ]  
> > },  
> > "publisher2" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 11,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 17  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher3" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 8,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher4" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 6,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > }, {  
> > "term" : "ABC1",  
> > "count" : 2  
> > } ]  
> > },  
> > "publisher10" : {  
> > "\_type" : "terms",  
> > "missing" : 289,  
> > "total" : 30,  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : "ABC",  
> > "count" : 18  
> > }, {  
> > "term" : "publisher",  
> > "count" : 2  
> > }, {  
> > "term" : "DEF",  
> > "count" : 2  
> > }, {  
> > "term" : "ABC1",  
> > "count" : 2  
> > }, {  
> > "term" : "test1",  
> > "count" : 1  
> > }, {  
> > "term" : "self",  
> > "count" : 1  
> > }, {  
> > "term" : "eva3",  
> > "count" : 1  
> > }, {  
> > "term" : "claire",  
> > "count" : 1  
> > }, {  
> > "term" : "ABC2",  
> > "count" : 1  
> > }, {  
> > "term" : "asdfa",  
> > "count" : 1  
> > } ]  
> > }  
> > }  
> > }
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.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).  
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:47am UTC](https://discuss.elastic.co/t/facet-count-strange-behaviour-different-result-for-different-size-of-most-frequent-terms/11064/10 "2017-07-06T02:47:37Z")

</div>


