# Terms facet with multi-fields and count

**URL:** <https://discuss.elastic.co/t/terms-facet-with-multi-fields-and-count/9710>\
**Category:** Elasticsearch\
**Created:** [November 14, 2012, 7:13am UTC](https://discuss.elastic.co/t/terms-facet-with-multi-fields-and-count/9710 "2012-11-14T07:13:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Runar\_Myklebust\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runar_myklebust_2/32/2047_2.png) [@Runar\_Myklebust\_2](https://discuss.elastic.co/u/Runar_Myklebust_2)\
**Post date:** [November 14, 2012, 7:13am UTC](https://discuss.elastic.co/t/terms-facet-with-multi-fields-and-count/9710/1 "2012-11-14T07:13:30Z")

</div>

Hi,

Is this a bug, or is my conception of how its supposed to be wrong?

If I have this query:

{  
"from" : 0,  
"size" : 200,  
"query" : {  
"filtered" : {  
"query" : {  
"match\_all" : { }  
}  
}  
},  
"facets" : {  
"specietypes" : {  
"terms" : {  
"fields" : [ "data\_person\_type", "data\_person\_gender",  
"data\_person\_drink" ],  
"size" : 3,  
"order" : "count"  
}  
}  
}  
}

I would recon that the result-set should contain the 3 hits with the  
largest count-value across the 3 fields? Using ES v 0.19.10, this test will  
fail when count is 3 (embedded client)

assertEquals( 4L, (long) results.get( "male" ) );  
assertEquals( 3L, (long) results.get( "human" ) );  
assertEquals( 3L, (long) results.get( "beer" ) );

instead of "human" with 3 hits, "robot" with 2 hits will be returned in the  
set of 3. When using a larger set, this test will pass, so the data set is  
ok.

--  
Runar Myklebust  
Enonic AS  
Senior Developer

[http://enonic.com/download](http://enonic.com/download)

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 14, 2012, 2:09pm UTC](https://discuss.elastic.co/t/terms-facet-with-multi-fields-and-count/9710/2 "2012-11-14T14:09:09Z")

</div>

You might be hitting this  
issue [Inconsistent facet counts · Issue #1832 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1832) As a  
workaround, try increasing "size" in facets from 3 to a larger number and  
see if it will improve the counts for the top 3 facets.

On Wednesday, November 14, 2012 2:13:55 AM UTC-5, Runar Myklebust wrote:

> Hi,
> 
> Is this a bug, or is my conception of how its supposed to be wrong?
> 
> If I have this query:
> 
> {  
> "from" : 0,  
> "size" : 200,  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "match\_all" : { }  
> }  
> }  
> },  
> "facets" : {  
> "specietypes" : {  
> "terms" : {  
> "fields" : [ "data\_person\_type", "data\_person\_gender",  
> "data\_person\_drink" ],  
> "size" : 3,  
> "order" : "count"  
> }  
> }  
> }  
> }
> 
> I would recon that the result-set should contain the 3 hits with the  
> largest count-value across the 3 fields? Using ES v 0.19.10, this test will  
> fail when count is 3 (embedded client)
> 
> assertEquals( 4L, (long) results.get( "male" ) );  
> assertEquals( 3L, (long) results.get( "human" ) );  
> assertEquals( 3L, (long) results.get( "beer" ) );
> 
> instead of "human" with 3 hits, "robot" with 2 hits will be returned in  
> the set of 3. When using a larger set, this test will pass, so the data set  
> is ok.
> 
> --  
> Runar Myklebust  
> Enonic AS  
> Senior Developer
> 
> [http://enonic.com/download](http://enonic.com/download)

--

---

<div class="post-metadata">

**Author:** ![Runar\_Myklebust\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runar_myklebust_2/32/2047_2.png) [@Runar\_Myklebust\_2](https://discuss.elastic.co/u/Runar_Myklebust_2)\
**Post date:** [November 14, 2012, 7:07pm UTC](https://discuss.elastic.co/t/terms-facet-with-multi-fields-and-count/9710/3 "2012-11-14T19:07:14Z")

</div>

Indeed, when I change to 1 shard, it works like expected. This happened  
during an integration test where only 6 documents where indexed, and with 4  
shards I guess this would be very visible.

Thanks!

On Wed, Nov 14, 2012 at 3:09 PM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> You might be hitting this issue  
> [Inconsistent facet counts · Issue #1832 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1832) As a  
> workaround, try increasing "size" in facets from 3 to a larger number and  
> see if it will improve the counts for the top 3 facets.
> 
> On Wednesday, November 14, 2012 2:13:55 AM UTC-5, Runar Myklebust wrote:
> 
> > Hi,
> > 
> > Is this a bug, or is my conception of how its supposed to be wrong?
> > 
> > If I have this query:
> > 
> > {  
> > "from" : 0,  
> > "size" : 200,  
> > "query" : {  
> > "filtered" : {  
> > "query" : {  
> > "match\_all" : { }  
> > }  
> > }  
> > },  
> > "facets" : {  
> > "specietypes" : {  
> > "terms" : {  
> > "fields" : [ "data\_person\_type", "data\_person\_gender",  
> > "data\_person\_drink" ],  
> > "size" : 3,  
> > "order" : "count"  
> > }  
> > }  
> > }  
> > }
> > 
> > I would recon that the result-set should contain the 3 hits with the  
> > largest count-value across the 3 fields? Using ES v 0.19.10, this test will  
> > fail when count is 3 (embedded client)
> > 
> > assertEquals( 4L, (long) results.get( "male" ) );  
> > assertEquals( 3L, (long) results.get( "human" ) );  
> > assertEquals( 3L, (long) results.get( "beer" ) );
> > 
> > instead of "human" with 3 hits, "robot" with 2 hits will be returned in  
> > the set of 3. When using a larger set, this test will pass, so the data set  
> > is ok.
> > 
> > --  
> > Runar Myklebust  
> > Enonic AS  
> > Senior Developer
> > 
> > [http://enonic.com/download](http://enonic.com/download)

--  
Runar Myklebust  
Enonic AS  
Senior Developer

[http://enonic.com/download](http://enonic.com/download)

--

---

<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:04am UTC](https://discuss.elastic.co/t/terms-facet-with-multi-fields-and-count/9710/4 "2017-07-06T03:04:14Z")

</div>


