# Has\_child query match children-less parent

**URL:** <https://discuss.elastic.co/t/has-child-query-match-children-less-parent/253325>\
**Category:** Elasticsearch\
**Created:** [October 26, 2020, 2:34pm UTC](https://discuss.elastic.co/t/has-child-query-match-children-less-parent/253325 "2020-10-26T14:34:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfferrao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rfferrao/32/76344_2.png) [@rfferrao](https://discuss.elastic.co/u/rfferrao)\
**Post date:** [October 26, 2020, 2:34pm UTC](https://discuss.elastic.co/t/has-child-query-match-children-less-parent/253325/1 "2020-10-26T14:34:04Z")

</div>

Is it possible to do this? Here's what I've tried:

```auto
{
  "query": {
    "bool": {
      "should": {
        "has_child": {
          "type": "group",
          "query": { "bool": { "should": { "match_all": { } } } },
          "inner_hits": { },
          "min_children": 0
        }
      }
    }
  }
}

```

Yet, even with `"min_children": 0` the only hits are the parent documents containing 1 or more children.

---

<div class="post-metadata">

**Author:** ![rfferrao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rfferrao/32/76344_2.png) [@rfferrao](https://discuss.elastic.co/u/rfferrao)\
**Post date:** [October 26, 2020, 3:36pm UTC](https://discuss.elastic.co/t/has-child-query-match-children-less-parent/253325/2 "2020-10-26T15:36:59Z")

</div>

Just found a solution, here's a way to do it:

```auto
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "my_join_field": "user"
        }
      },
      "should": [
        {
          "bool": {
            "must_not": [
              {
                "has_child": {
                  "type": "group",
                  "query": {
                    "match_all": {}
                  }
                }
              }
            ]
          }
        },
        {
          "has_child": {
            "inner_hits": {},
            "type": "group",
            "query": {
              "match_all": {}
            }
          }
        }
      ]
    }
  }
}

```

---

<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:** [November 23, 2020, 3:37pm UTC](https://discuss.elastic.co/t/has-child-query-match-children-less-parent/253325/3 "2020-11-23T15:37:01Z")

</div>

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