Get _parent source fields from child document

Hi all,

actually here is my question:


Maybe some of you have some ideas how to do it.

$reqParams['body'] = array(
'query' => array(
'has_parent' => [
'parent_type' => 'user',
'query' => [
'match_all' => []
],
'inner_hits' => [
'_source' => ['*']
]
],
)
);

I think this query from your question on SO is the right direction. I don't fully understand your question, but you do two kinds of filtering on both parent and child side.

You can either do filter by query. You add a query inside the has_parent's inner query instead of the match_all query to filter by properties on the parent side. Or build a bool query, add the has_parent query as must clause and then define another must query with a query to filter on the child side.

Source filtering can be applied on the parent side (modifying the _source filtering inside the inner_hits element) or child side (adding a _source filtering as top level element to the search request).

Thank YOU!

This is what I did and it works