Has_child query match children-less parent

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

{
  "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.

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

{
  "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": {}
            }
          }
        }
      ]
    }
  }
}

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