# Nested filter and parents in Aggregations

**URL:** <https://discuss.elastic.co/t/nested-filter-and-parents-in-aggregations/141741>\
**Category:** Elasticsearch\
**Created:** [July 26, 2018, 10:56am UTC](https://discuss.elastic.co/t/nested-filter-and-parents-in-aggregations/141741 "2018-07-26T10:56:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan\_Daratha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephan_daratha/32/32177_2.png) [@Stephan\_Daratha](https://discuss.elastic.co/u/Stephan_Daratha)\
**Post date:** [July 26, 2018, 10:56am UTC](https://discuss.elastic.co/t/nested-filter-and-parents-in-aggregations/141741/1 "2018-07-26T10:56:54Z")

</div>

Hi,

I have a little problem with aggregations.

Is it possible to filter parents in aggregations.

If i try

```
> "aggregations": {
> "sleeping": {
> "filter": {
> "bool": {
> "must": [
> {
> "term": {
> "objectGroup": "housing"
> }
> },
> {
> "nested": {
> "path": "objectMemberInformation",
> "query": {
> "bool": {
> "must": [
> {
> "term": {
> "objectMemberInformation.objectNumber": "5174602"
> }
> }
> ]
> }
> }
> }
> }
> ]
> }
> },
> "aggregations": {
> "sleeping": {
> "nested": {
> "path": "objectMemberInformation"
> },
> "aggregations": {
> "sleepingCount": {
> "range": {
> "field": "objectMemberInformation.detailRoomSleeping",
> "ranges": [
> {
> "from": 1
> },
> {
> "from": 2
> },
> {
> "from": 3
> },
> {
> "from": 4
> },
> {
> "from": 5
> },
> {
> "from": 6
> },
> {
> "from": 7
> },
> {
> "from": 8
> }
> ]
> }              
> }
> }
> }
> }
> }
> }

```

The filter of objectNumber is not used in aggregations "sleepingCount"

If I start the aggregation with nested and ignore the filter "housing" it works.

```
> "aggregations": {
> "sleeping": {
> "nested": {
> "path": "objectMemberInformation"
> },
> "aggregations": {
> "sleeping": {
> "filter": {
> "bool": {
> "must": [
> {
> "term": {
> "objectMemberInformation.objectNumber": "5174602"
> }
> }
> ]
> }
> },
> "aggregations": {
> "sleepingCount": {
> "range": {
> "field": "objectMemberInformation.detailRoomSleeping",
> "ranges": [
> {
> "from": 1
> },
> {
> "from": 2
> },
> {
> "from": 3
> },
> {
> "from": 4
> },
> {
> "from": 5
> },
> {
> "from": 6
> },
> {
> "from": 7
> },
> {
> "from": 8
> }
> ]
> }
> }
> }
> }
> }
> }
> }

```

Is it possible to combine them?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![Stephan\_Daratha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephan_daratha/32/32177_2.png) [@Stephan\_Daratha](https://discuss.elastic.co/u/Stephan_Daratha)\
**Post date:** [July 26, 2018, 11:28am UTC](https://discuss.elastic.co/t/nested-filter-and-parents-in-aggregations/141741/2 "2018-07-26T11:28:27Z")

</div>

Sorry, it already works

```
> "aggregations": {
> "sleeping": {
> "filter": {
> "bool": {
> "must": [
> {
> "term": {
> "objectGroup": "housing"
> }
> }
> ]
> }
> },
> "aggregations": {
> "sleeping": {
> "nested": {
> "path": "objectMemberInformation"
> },
> "aggregations": {
> "sleeping": {
> "filter": {                
> "bool": {
> "must": [
> {
> "term": {
> "objectMemberInformation.objectNumber": "5174602"
> }
> }
> ]                  
> }
> },            
> "aggregations": {
> "sleepingCount": {
> "range": {
> "field": "objectMemberInformation.detailRoomSleeping",
> "ranges": [
> {
> "from": 1
> },
> {
> "from": 2
> },
> {
> "from": 3
> },
> {
> "from": 4
> },
> {
> "from": 5
> },
> {
> "from": 6
> },
> {
> "from": 7
> },
> {
> "from": 8
> }
> ]
> }
> }
> }
> }
> }
> }
> }
> }
> }
```

---

<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:** [August 23, 2018, 11:43am UTC](https://discuss.elastic.co/t/nested-filter-and-parents-in-aggregations/141741/3 "2018-08-23T11:43:24Z")

</div>

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