Parent Child always query parent but might filter children?

So I'm trying to determine the best way to handle the house hold occupant kind of question for our membership roster.

We would always query something of the household. Address, or something like that, but at times, we would want the nested or child information filtered as well.

For example, some times I might want just the household information, address.
Other times, I might want the address, but only a subset of the occupants returned. For example, only those occupants over the age of 40.

In all cases, we would want the parent information back (household in my case), but may optionally also want back a subset of the occupants as well.

I thought of a parent-child... But I can't seem to get a document back that has both parent and child info combined.

I thought about 2 queries, but if I can combine it into one, I'm hoping I can get better throughput, etc.

I was also thinking of nested, (We would never just query the occupant's info). But I'd want to filter out the nested parts I don't want, etc.

So, what makes the sense for a household-occupant configuration?

Thanks up front,
Nick

You can use inner_hits to return both parent and child.

{
  "query": {
    "bool": {
      "must": [
        {
          "has_parent": {
            "parent_type": "question",
            "query": {
              "query_string": {
                "query": "text: question  "
              }
            },
           "inner_hits": {}
          }
        },
        {
          "query_string": {
            "query": "text:  answer "
          }
        }
      ]
    }
  }
}

It return matched child documents with inner hits that include its parent document.

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