# Term facet bug on multi-shard indexes

**URL:** https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12739
**Category:** Elasticsearch
**Created:** [July 10, 2013, 11:54am UTC](https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12739 "2013-07-10T11:54:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Gregory](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@Gregory](https://discuss.elastic.co/u/Gregory)
#### Post date: [July 10, 2013, 11:54am UTC](https://discuss.elastic.co/t/term-facet-bug-on-multi-shard-indexes/12739/1 "2013-07-10T11:54:06Z")

</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** &nbsp;times:  
  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **0** /' -d '{ "value" : **5** &nbsp;}'  
  
execute **1** &nbsp;time:  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **0** /' -d '{ "value" : **7** &nbsp;}'  
  
execute **1** &nbsp;time:  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **1** /' -d '{ "value" : **5** &nbsp;}'  
  
execute **2** &nbsp;times:  
$ curl -XPOST '[http://localhost:9200/test/mytype?routing=](http://localhost:9200/test/mytype?routing=) **1** /' -d '{ "value" : **7** &nbsp;}'  
  
After that, we have seven documents, four of them on first shard (routing 0) and three on the second shard.  
  
Now execute query:  
  
{  
  
&nbsp; "facets": {  
  
&nbsp; &nbsp; "value": {  
  
&nbsp; &nbsp; &nbsp; "terms": {  
  
&nbsp; &nbsp; &nbsp; &nbsp; "field": "value",  
  
&nbsp; &nbsp; &nbsp; &nbsp; "size": 1  
  
&nbsp; &nbsp; &nbsp; }  
  
&nbsp; &nbsp; }  
  
&nbsp; },  
  
&nbsp; "query": { "match\_all": {} },  
  
&nbsp; "size": 0  
  
}  
  
The response is:  
  
{  
  
&nbsp; &nbsp; &nbsp; &nbsp; .....  
  
&nbsp; &nbsp; &nbsp; &nbsp; "facets" : {  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "value" : {  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "\_type" : "terms",  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "missing" : 0,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "total" : 7,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "other" : 4,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "terms" : [{  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "term" : 5,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "count" : 3  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
  
&nbsp; &nbsp; &nbsp; &nbsp; }  
  
}  
  
But frequency of '5' term is 4!  
  
If I change facet size to 2, I will receive right response:  
  
{  
  
&nbsp; &nbsp; &nbsp; &nbsp; .....  
  
&nbsp; &nbsp; &nbsp; &nbsp; "facets" : {  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "value" : {  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "\_type" : "terms",  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "missing" : 0,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "total" : 7,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "other" : 0,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "terms" : [{  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "term" : 5,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "count" : 4  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "term" : 7,  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "count" : 3  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]  
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
  
&nbsp; &nbsp; &nbsp; &nbsp; }  
  
}  
  
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?

---

<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/12739/2 "2017-07-06T02:27:12Z")

</div>


