# Occurance per another field

**URL:** <https://discuss.elastic.co/t/occurance-per-another-field/5808>\
**Category:** Elasticsearch\
**Created:** [November 8, 2011, 8:22am UTC](https://discuss.elastic.co/t/occurance-per-another-field/5808 "2011-11-08T08:22:26Z")\
**Posts on this page:** 4\
**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:** [November 8, 2011, 8:22am UTC](https://discuss.elastic.co/t/occurance-per-another-field/5808/1 "2011-11-08T08:22:26Z")

</div>

Hi ,

I have documents which are described in the

GIST - [https://gist.github.com/1347280](https://gist.github.com/1347280)

In each document i have many companies. (Which i am putting in companies  
list)  
For each company i have attributes tag with values like "software" ,  
"product" , "service" ... etc

When a search hits , i want to know which all companies are included in the  
search (This can be done using term facets)  
Now under each company , i want to know its tags.

Eg: Now when a query hit , the facet result should be something like

comapy : [ { name : yahoo , hits : 3 , tags : [ internet , software ,  
product ] } ,  
{ name : IBM , hits : 2 , tags : [software , service]}]

I figured out it has something to do with term\_stat , but am not getting  
it to work.

Can someone give an insight on this.

Thanks  
Vineeth

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 9, 2011, 10:41am UTC](https://discuss.elastic.co/t/occurance-per-another-field/5808/2 "2011-11-09T10:41:23Z")

</div>

It has nothing to do with terms stats. You can't do this with elasticsearch.

On Tue, Nov 8, 2011 at 10:22 AM, Vineeth Mohan [vineethmohan@algotree.com](mailto:vineethmohan@algotree.com)wrote:

> Hi ,
> 
> I have documents which are described in the
> 
> GIST - [gist:1347280 · GitHub](https://gist.github.com/1347280)
> 
> In each document i have many companies. (Which i am putting in companies  
> list)  
> For each company i have attributes tag with values like "software" ,  
> "product" , "service" ... etc
> 
> When a search hits , i want to know which all companies are included in  
> the search (This can be done using term facets)  
> Now under each company , i want to know its tags.
> 
> Eg: Now when a query hit , the facet result should be something like
> 
> comapy : [ { name : yahoo , hits : 3 , tags : [ internet , software ,  
> product ] } ,  
> { name : IBM , hits : 2 , tags : [software , service]}]
> 
> I figured out it has something to do with term\_stat , but am not getting  
> it to work.
> 
> Can someone give an insight on this.
> 
> 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:** [November 9, 2011, 11:18am UTC](https://discuss.elastic.co/t/occurance-per-another-field/5808/3 "2011-11-09T11:18:42Z")

</div>

I came up with a workaround here

Now instead of

list : [ {company : yahoo , tag : internet } ,  
{company : IBM , tag : software }]

It would be

list : [ {company : yahoo , yahoo : internet } ,  
{company : IBM , IBM : software }]

This way , i can first search for the company and with company name as  
field name , i can run the facets to get the related details.

Thanks  
Vineeth

On Wed, Nov 9, 2011 at 4:11 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> It has nothing to do with terms stats. You can't do this with  
> elasticsearch.
> 
> On Tue, Nov 8, 2011 at 10:22 AM, Vineeth Mohan [vineethmohan@algotree.com](mailto:vineethmohan@algotree.com)wrote:
> 
> > Hi ,
> > 
> > I have documents which are described in the
> > 
> > GIST - [gist:1347280 · GitHub](https://gist.github.com/1347280)
> > 
> > In each document i have many companies. (Which i am putting in companies  
> > list)  
> > For each company i have attributes tag with values like "software" ,  
> > "product" , "service" ... etc
> > 
> > When a search hits , i want to know which all companies are included in  
> > the search (This can be done using term facets)  
> > Now under each company , i want to know its tags.
> > 
> > Eg: Now when a query hit , the facet result should be something like
> > 
> > comapy : [ { name : yahoo , hits : 3 , tags : [ internet , software ,  
> > product ] } ,  
> > { name : IBM , hits : 2 , tags : [software , service]}]
> > 
> > I figured out it has something to do with term\_stat , but am not getting  
> > it to work.
> > 
> > Can someone give an insight on this.
> > 
> > Thanks  
> > Vineeth

---

<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:49am UTC](https://discuss.elastic.co/t/occurance-per-another-field/5808/4 "2017-07-06T03:49:20Z")

</div>


