# Child document grouping and filtering

**URL:** <https://discuss.elastic.co/t/child-document-grouping-and-filtering/67409>\
**Category:** Elasticsearch\
**Created:** [November 28, 2016, 10:35pm UTC](https://discuss.elastic.co/t/child-document-grouping-and-filtering/67409 "2016-11-28T22:35:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tavoaqp](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@tavoaqp](https://discuss.elastic.co/u/tavoaqp)\
**Post date:** [November 28, 2016, 10:35pm UTC](https://discuss.elastic.co/t/child-document-grouping-and-filtering/67409/1 "2016-11-28T22:35:29Z")

</div>

Hi there

Suppose you have a document like this:

listing: {  
id: "1",  
name: "name1",  
upinterval:[{start:"2016-10-01",end:"2016-12-25",id:"u11"}],  
downinterval:[{start:"2016-10-10",end:"2016-10-29",id:"d11"},{start:"2016-12-05",end:"2016-12-10",id:"d12"}]  
},  
listing: {  
id: "2",  
name: "name2",  
upinterval:[{start:"2016-11-28",end:"2017-01-25",id:"u21"}],  
downinterval:[{start:"2016-12-24",end:"2017-01-01",id:"d21"},{start:"2017-01-10",end:"2017-01-15",id:"d22"}]  
}

I've tried (without success) a query to retrieve a list of documents containing an upinterval that starts before 2017-01-05 and within each document I want to count the number of downintervals:

query={  
aggs: {  
filtered: {  
filter:{ range: { "upinterval.start": { lte: "2017-01-05" }, \_name: "avail1" } }  
},  
aggs:{  
nested: {  
path: "downinterval"  
},  
aggs: {  
unavail\_count: {  
cardinality: {  
field: "[downinterval.id](http://downinterval.id)"  
}  
}  
}  
}  
}  
}

I pretend to even filter downintervals but I decided to attack a simpler problem.  
Thanks for any help

---

<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:** [December 26, 2016, 10:36pm UTC](https://discuss.elastic.co/t/child-document-grouping-and-filtering/67409/2 "2016-12-26T22:36:04Z")

</div>

Closed on December 26, 2016, 10:36pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
