# Has\_child filter does't work as expected with bool filter?

**URL:** https://discuss.elastic.co/t/has-child-filter-doest-work-as-expected-with-bool-filter/33819
**Category:** Elasticsearch
**Created:** [November 4, 2015, 11:46pm UTC](https://discuss.elastic.co/t/has-child-filter-doest-work-as-expected-with-bool-filter/33819 "2015-11-04T23:46:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Anton\_Bogdanovich](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anton_bogdanovich/32/44922_2.png) [@Anton\_Bogdanovich](https://discuss.elastic.co/u/Anton_Bogdanovich)
#### Post date: [November 4, 2015, 11:46pm UTC](https://discuss.elastic.co/t/has-child-filter-doest-work-as-expected-with-bool-filter/33819/1 "2015-11-04T23:46:34Z")

</div>

I have a query to return all distinct parent ids that have children with open\_flag=1 excluding parent ids that have children with open\_flag=0 (open\_flag is either 1 or 0 for all chidren). It returns much more results than expected. The list of aggregated contact\_ids does include ids where open\_flag=0.

The query is performed on alias that have 3 indexes. Elasticsearch version is 1.4.5

```
{
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "has_child": {
                                "type": "event",
                                "filter": {
                                    "bool": {
                                        "must": [
                                            {
                                                "term": {
                                                    "open_flag": 1
                                                }
                                            },
                                        ]
                                    }
                                }
                            }
                        }
                    ],
                    "must_not": [
                       {
                           "has_child": {
                                "type": "event",
                                "filter": {
                                    "bool": {
                                        "must": [
                                            {
                                                "term": {
                                                    "open_flag": 0
                                                }
                                            }
                                            
                                        ],
                                        "must_not": []
                                    }
                                }
                            }
                       }
                    ]
                }
            }
        }
    },
    "fields": [],
    "size": 0,
    "aggs": {
        "contact_ids": {
            "terms": {
                "field": "contact_id",
                "size": 1000
            }
        },
        "total_count": {
            "cardinality": {
                "field": "contact_id",
                "precision_threshold": 40000
            }
        }
    }
}
```

---

<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 5, 2017, 11:40pm UTC](https://discuss.elastic.co/t/has-child-filter-doest-work-as-expected-with-bool-filter/33819/2 "2017-07-05T23:40:28Z")

</div>


