# How to query and return whether a result has at least one child?

**URL:** <https://discuss.elastic.co/t/how-to-query-and-return-whether-a-result-has-at-least-one-child/162713>\
**Category:** Elasticsearch\
**Created:** [January 2, 2019, 8:51pm UTC](https://discuss.elastic.co/t/how-to-query-and-return-whether-a-result-has-at-least-one-child/162713 "2019-01-02T20:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caleb\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caleb_ott/32/8115_2.png) [@Caleb\_Ott](https://discuss.elastic.co/u/Caleb_Ott)\
**Post date:** [January 2, 2019, 8:51pm UTC](https://discuss.elastic.co/t/how-to-query-and-return-whether-a-result-has-at-least-one-child/162713/1 "2019-01-02T20:51:29Z")

</div>

Hello, I have a type (document) which has a child type (document\_partials). Not all documents have a document\_partial, but some do.

I want a query that lets me search against my document type and returns if it has a child (document\_partial) or not. I want to return all results that match my search query, but I also want to get back whether the result has a child or not.

I am running into the issue of not being able to search for items that do and don't have children when using has\_child. Similar to needing to min\_children to 0 like in this issue: [https://github.com/elastic/elasticsearch/issues/21224](https://github.com/elastic/elasticsearch/issues/21224).

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 2, 2019, 9:02pm UTC](https://discuss.elastic.co/t/how-to-query-and-return-whether-a-result-has-at-least-one-child/162713/2 "2019-01-02T21:02:35Z")

</div>

You can either wrap `has_child` into [function score](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/query-dsl-function-score-query.html) and check the score (if you are not using score in your search) or you can add it as a should clause and [name it](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-named-queries-and-filters.html).

---

<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:** [January 30, 2019, 9:02pm UTC](https://discuss.elastic.co/t/how-to-query-and-return-whether-a-result-has-at-least-one-child/162713/3 "2019-01-30T21:02:45Z")

</div>

Closed on January 30, 2019, 9:02pm UTC

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