# Find percentage of facets matched rather than number of matched documents

**URL:** <https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983>\
**Category:** Elasticsearch\
**Created:** [September 11, 2012, 8:15am UTC](https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983 "2012-09-11T08:15:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vineeth\_mohan](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vineeth\_mohan](https://discuss.elastic.co/u/vineeth_mohan)\
**Post date:** [September 11, 2012, 8:15am UTC](https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983/1 "2012-09-11T08:15:53Z")

</div>

Hi ,

Is there any way i can find the percentage of facet name matched for a  
query rather than the number of documents having that facet.

That is , instead of telling that there are 1000 documents which have a  
facet yahoo , i want the result which tells me that there are 60% document  
which matches the query and have a facet yahoo. Rest 40% of documents which  
have the facet yahoo dont match the query.

Thanks  
Vineeth

--

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [September 11, 2012, 8:32am UTC](https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983/2 "2012-09-11T08:32:30Z")

</div>

Hi,

you can easily calculate the value from hits.total and count of particular  
facet.

Regards,  
Lukas

On Tue, Sep 11, 2012 at 10:15 AM, Vineeth Mohan  
[vineethmohan@algotree.com](mailto:vineethmohan@algotree.com)wrote:

> Hi ,
> 
> Is there any way i can find the percentage of facet name matched for a  
> query rather than the number of documents having that facet.
> 
> That is , instead of telling that there are 1000 documents which have a  
> facet yahoo , i want the result which tells me that there are 60% document  
> which matches the query and have a facet yahoo. Rest 40% of documents which  
> have the facet yahoo dont match the query.
> 
> Thanks  
> Vineeth
> 
> --

--

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vineeth\_mohan](https://discuss.elastic.co/u/vineeth_mohan)\
**Post date:** [September 11, 2012, 8:55am UTC](https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983/3 "2012-09-11T08:55:59Z")

</div>

That is also a useful variable but what i mean was not that.

Lets say there are total of 30 feeds in an index and for the field Country  
, there are 10 India , 5 US and 3 UK.

No for the query "growth" , i got 20 hits , out of which for the field  
country there are 5 India , 2 US and 1 UK.

What i want is for the facet Country:India , i want the result as India -  
50% , US = 40% , UK = 33.3%

Thanks  
Vineeth

On Tue, Sep 11, 2012 at 2:02 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:

> Hi,
> 
> you can easily calculate the value from hits.total and count of particular  
> facet.
> 
> Regards,  
> Lukas
> 
> On Tue, Sep 11, 2012 at 10:15 AM, Vineeth Mohan \<[vineethmohan@algotree.com](mailto:vineethmohan@algotree.com)
> 
> > wrote:
> 
> > Hi ,
> > 
> > Is there any way i can find the percentage of facet name matched for a  
> > query rather than the number of documents having that facet.
> > 
> > That is , instead of telling that there are 1000 documents which have a  
> > facet yahoo , i want the result which tells me that there are 60% document  
> > which matches the query and have a facet yahoo. Rest 40% of documents which  
> > have the facet yahoo dont match the query.
> > 
> > Thanks
> > 
> > ```
> > Vineeth
> > 
> > ```
> > 
> > --
> 
> --

--

---

<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:** [September 11, 2012, 6:00pm UTC](https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983/4 "2012-09-11T18:00:57Z")

</div>

Don't quite understand your math. India 50%? Depending on what you are  
after, it should either be 5/20 or 5/8. I can understand your problem  
better if you can explain how those percentages are calculated.

In your first example, you have the percentage for Yahoo vs.  
everything else. In your second example, you should percentages for  
multiple values: India, US, and UK. Which one do you want? First one  
is tricky, I would probably use two facets, one with a filter, and the  
other one without, and then calculate percentages on the client side.

--

Ivan

On Tue, Sep 11, 2012 at 1:55 AM, Vineeth Mohan  
[vineethmohan@algotree.com](mailto:vineethmohan@algotree.com) wrote:

> That is also a useful variable but what i mean was not that.
> 
> Lets say there are total of 30 feeds in an index and for the field Country ,  
> there are 10 India , 5 US and 3 UK.
> 
> No for the query "growth" , i got 20 hits , out of which for the field  
> country there are 5 India , 2 US and 1 UK.
> 
> What i want is for the facet Country:India , i want the result as India -  
> 50% , US = 40% , UK = 33.3%
> 
> Thanks  
> Vineeth
> 
> On Tue, Sep 11, 2012 at 2:02 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:
> 
> > Hi,
> > 
> > you can easily calculate the value from hits.total and count of particular  
> > facet.
> > 
> > Regards,  
> > Lukas
> > 
> > On Tue, Sep 11, 2012 at 10:15 AM, Vineeth Mohan  
> > [vineethmohan@algotree.com](mailto:vineethmohan@algotree.com) wrote:
> > 
> > > Hi ,
> > > 
> > > Is there any way i can find the percentage of facet name matched for a  
> > > query rather than the number of documents having that facet.
> > > 
> > > That is , instead of telling that there are 1000 documents which have a  
> > > facet yahoo , i want the result which tells me that there are 60% document  
> > > which matches the query and have a facet yahoo. Rest 40% of documents which  
> > > have the facet yahoo dont match the query.
> > > 
> > > Thanks
> > > 
> > > ```
> > > Vineeth
> > > 
> > > ```
> > > 
> > > --
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [September 14, 2012, 3:56pm UTC](https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983/5 "2012-09-14T15:56:21Z")

</div>

On 9/11/2012 1:55 AM, Vineeth Mohan wrote:

> That is also a useful variable but what i mean was not that.
> 
> Lets say there are total of 30 feeds in an index and for the field  
> Country , there are 10 India , 5 US and 3 UK.
> 
> No for the query "growth" , i got 20 hits , out of which for the field  
> country there are 5 India , 2 US and 1 UK.
> 
> What i want is for the facet Country:India , i want the result as  
> India - 50% , US = 40% , UK = 33.3%
> 
> Thanks  
> Vineeth

I also don't see your math, but I think it is  
india = 5 new ones (I suppose this means there 15 total both old and  
new) which is a growth of 50% over the 10 original.

I'd just to two facets,  
1st facet base counts  
2nd facet counts growth for period  
and do the division yourself.  
But I think you could do both in the same search request.

-Paul

--

---

<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:12am UTC](https://discuss.elastic.co/t/find-percentage-of-facets-matched-rather-than-number-of-matched-documents/8983/6 "2017-07-06T03:12:42Z")

</div>


