# Return parents with or without children

**URL:** <https://discuss.elastic.co/t/return-parents-with-or-without-children/101721>\
**Category:** Elasticsearch\
**Created:** [September 25, 2017, 2:39pm UTC](https://discuss.elastic.co/t/return-parents-with-or-without-children/101721 "2017-09-25T14:39:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjes](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@benjes](https://discuss.elastic.co/u/benjes)\
**Post date:** [September 25, 2017, 2:39pm UTC](https://discuss.elastic.co/t/return-parents-with-or-without-children/101721/1 "2017-09-25T14:39:12Z")

</div>

Hi,

I've got a parent child model (see [Reindexing Elasticsearch index with parent and child relationship](https://discuss.elastic.co/t/reindexing-elasticsearch-index-with-parent-and-child-relationship/101331)) and I want to run a query that returns a list of all (or filtered) documents. In that list I want to have inner\_hits when the document has children but it should also include documents that do not have children!

I currently have:

```
{
      "query": {
      	"bool": {
      		"must":[ {
      			"match_all": {}	
      		},{
    		    "has_child": {
    		      "type": "child_message",
    		      "query": {
    		        "match_all": {}
    		      },
    		      "inner_hits": {}    
    		    }
    	    }]
      	}
      }
    }

```

But this only returns documents that do have children, not documents that don't have children. What do I need to do to get all document that match the original search whether they have children or not but if they have children they should be included in inner\_hits

---

<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:** [October 23, 2017, 2:39pm UTC](https://discuss.elastic.co/t/return-parents-with-or-without-children/101721/2 "2017-10-23T14:39:32Z")

</div>

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