# Term facet bug on multi-shard indexes

**URL:** https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12740
**Category:** Elasticsearch
**Created:** [July 10, 2013, 12:13pm UTC](https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12740 "2013-07-10T12:13:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![gregory\_bityukov](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@gregory\_bityukov](https://discuss.elastic.co/u/gregory_bityukov)
#### Post date: [July 10, 2013, 12:13pm UTC](https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12740/1 "2013-07-10T12:13:46Z")

</div>

Term facet doesn't work correct when index consists from several shards and  
terms frequency differs on sundry shards.  
Here is instruction how to reproduce that bug:

First of all, we need to create index 'test' within 2 shards. After that,  
execute **3** times:  
  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **0** /' -d '{  
"value" : **5** }'  
  
execute **1** time:  
  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **0** /' -d '{  
"value" : **7** }'  
  
execute **1** time:  
  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **1** /' -d '{  
"value" : **5** }'  
  
execute **2** times:  
  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **1** /' -d '{  
"value" : **7** }'  
  
After that, we have seven documents, four of them on first shard (routing  
0) and three on the second shard.  
Now execute query:  
{  
"facets": {  
"value": {  
"terms": {  
"field": "value",  
"size": 1  
}  
}  
},  
"query": { "match\_all": {} },  
"size": 0  
}  
The response is:  
{  
.....  
"facets" : {  
"value" : {  
"\_type" : "terms",  
"missing" : 0,  
"total" : 7,  
"other" : 4,  
"terms" : [{  
"term" : 5,  
"count" : 3  
}  
]  
}  
}  
}  
But frequency of '5' term is 4!  
If I change facet size to 2, I will receive right response:  
{  
.....  
"facets" : {  
"value" : {  
"\_type" : "terms",  
"missing" : 0,  
"total" : 7,  
"other" : 0,  
"terms" : [{  
"term" : 5,  
"count" : 4  
}, {  
"term" : 7,  
"count" : 3  
}  
]  
}  
}  
}  
Elastic Search engine takes [size] of most frequent terms on each shard,  
not on whole index. It's ok for query\_and\_fetch request, but when I execute  
query\_then\_fetch I expect to receive right answer.  
Can you fix that bug, please?

--  
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: [July 10, 2013, 12:55pm UTC](https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12740/2 "2013-07-10T12:55:57Z")

</div>

I suppose that you are talking about this issue: [terms facet gives wrong count with n\_shards \> 1 · Issue #1305 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1305?source=cc)

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

Le 10 juil. 2013 à 14:13, [gregory.bityukov@gmail.com](mailto:gregory.bityukov@gmail.com) a écrit :

> Term facet doesn't work correct when index consists from several shards and terms frequency differs on sundry shards.  
> Here is instruction how to reproduce that bug:
> 
> First of all, we need to create index 'test' within 2 shards. After that, execute **3** times:  
>   
> $ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **0** /' -d '{ "value" : **5** }'  
>   
> execute **1** time:  
>   
> $ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **0** /' -d '{ "value" : **7** }'  
>   
> execute **1** time:  
>   
> $ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **1** /' -d '{ "value" : **5** }'  
>   
> execute **2** times:  
>   
> $ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **1** /' -d '{ "value" : **7** }'  
>   
> After that, we have seven documents, four of them on first shard (routing 0) and three on the second shard.  
> Now execute query:  
> {  
> "facets": {  
> "value": {  
> "terms": {  
> "field": "value",  
> "size": 1  
> }  
> }  
> },  
> "query": { "match\_all": {} },  
> "size": 0  
> }  
> The response is:  
> {  
> .....  
> "facets" : {  
> "value" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "total" : 7,  
> "other" : 4,  
> "terms" : [{  
> "term" : 5,  
> "count" : 3  
> }  
> ]  
> }  
> }  
> }  
> But frequency of '5' term is 4!  
> If I change facet size to 2, I will receive right response:  
> {  
> .....  
> "facets" : {  
> "value" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "total" : 7,  
> "other" : 0,  
> "terms" : [{  
> "term" : 5,  
> "count" : 4  
> }, {  
> "term" : 7,  
> "count" : 3  
> }  
> ]  
> }  
> }  
> }  
> Elastic Search engine takes [size] of most frequent terms on each shard, not on whole index. It's ok for query\_and\_fetch request, but when I execute query\_then\_fetch I expect to receive right answer.  
> Can you fix that bug, please?
> 
> --  
> 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:27am UTC](https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12740/3 "2017-07-06T02:27:11Z")

</div>


