# Multi-field Facet Is it possible not double count documents?

**URL:** <https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460>\
**Category:** Elasticsearch\
**Created:** [January 22, 2013, 9:31pm UTC](https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460 "2013-01-22T21:31:57Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [January 22, 2013, 9:31pm UTC](https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460/1 "2013-01-22T21:31:57Z")

</div>

Looks like a multi-field facet counting matches rather than documents  
resulting in double-counting documents. Is it possible to control this  
behavior? Wold be nice to have a flag in facet def. to select desired  
behavior - it could be very confusing in some use cases to have more  
matches on a facet than you have documents.

Thank you,  
Alex

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 22, 2013, 10:18pm UTC](https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460/2 "2013-01-22T22:18:45Z")

</div>

You can use a script field with the terms facet where the script is  
the aggregation of the two fields.

--  
Ivan

On Tue, Jan 22, 2013 at 1:31 PM, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) wrote:

> Looks like a multi-field facet counting matches rather than documents  
> resulting in double-counting documents. Is it possible to control this  
> behavior? Wold be nice to have a flag in facet def. to select desired  
> behavior - it could be very confusing in some use cases to have more  
> matches on a facet than you have documents.
> 
> Thank you,  
> Alex
> 
> --

--

---

<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:** [January 22, 2013, 11:48pm UTC](https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460/3 "2013-01-22T23:48:15Z")

</div>

Thank you Ivan but wouldn't I get a big hit on performance? Simple term  
facet I assume is evaluated using inverted index while script based faced  
will be evaluated by loading and faceting every document. In any case  
ability to double or not-double counting would be a very helpful feature to  
have. I would say not double-counting seems to be a more common need then  
the opposite

On Tue, Jan 22, 2013 at 5:18 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> You can use a script field with the terms facet where the script is  
> the aggregation of the two fields.
> 
> --  
> Ivan
> 
> On Tue, Jan 22, 2013 at 1:31 PM, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) wrote:
> 
> > Looks like a multi-field facet counting matches rather than documents  
> > resulting in double-counting documents. Is it possible to control this  
> > behavior? Wold be nice to have a flag in facet def. to select desired  
> > behavior - it could be very confusing in some use cases to have more  
> > matches on a facet than you have documents.
> > 
> > Thank you,  
> > Alex
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [January 23, 2013, 9:58am UTC](https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460/4 "2013-01-23T09:58:09Z")

</div>

That's odd. I tought a facet count was always made per doc.  
Could it be that your facet is a nested facet? In witch case the count  
would be made by sub-doc, thus resulting in a total greater than your  
number of docs. (If I am not mistaken)

Le mardi 22 janvier 2013 22:31:57 UTC+1, AlexR a écrit :

> Looks like a multi-field facet counting matches rather than documents  
> resulting in double-counting documents. Is it possible to control this  
> behavior? Wold be nice to have a flag in facet def. to select desired  
> behavior - it could be very confusing in some use cases to have more  
> matches on a facet than you have documents.
> 
> Thank you,  
> Alex

--

---

<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:** [January 23, 2013, 1:11pm UTC](https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460/5 "2013-01-23T13:11:07Z")

</div>

Actually I do not know if it does. I am very new to ES. I just assumed it takes number of top teems and finds counts for them because queries with large result set did mot seem ti be much slower than smal ones. I need to eead up on lucine stoeage organization...

--

---

<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:55am UTC](https://discuss.elastic.co/t/multi-field-facet-is-it-possible-not-double-count-documents/10460/6 "2017-07-06T02:55:02Z")

</div>


