# Filter on aggregation over nested docs

**URL:** <https://discuss.elastic.co/t/filter-on-aggregation-over-nested-docs/14558>\
**Category:** Elasticsearch\
**Created:** [November 23, 2013, 7:43am UTC](https://discuss.elastic.co/t/filter-on-aggregation-over-nested-docs/14558 "2013-11-23T07:43:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohan\_choudhary](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@rohan\_choudhary](https://discuss.elastic.co/u/rohan_choudhary)\
**Post date:** [November 23, 2013, 7:43am UTC](https://discuss.elastic.co/t/filter-on-aggregation-over-nested-docs/14558/1 "2013-11-23T07:43:35Z")

</div>

Suppose my data consists of businesses and users, who review the businesses  
and stay in a particular state. Using the nested structure lets suppose we  
store businesses with users as nested docs:  
{  
"name": "ABC"  
"users": [  
{"name": "Jack",  
"state": "CA"  
},  
{  
"name": "Jill",  
"state": "NY"  
}  
]  
}

I want to do a filter of the following nature:

List all businesses which have atleast 4 users from state: CA, which have  
reviewed the business.

Ideally this is about putting a facet on top of nested docs and then using  
this as a filter. How will that be done using current functionality of  
ElasticSearch ?

Thanks in advance !

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:05am UTC](https://discuss.elastic.co/t/filter-on-aggregation-over-nested-docs/14558/2 "2017-07-06T02:05:10Z")

</div>

Closed on July 6, 2017, 2:05am UTC


