ElasticSearch include parent source in child search

I have a parent/child relationship between an user and many posts.
I know that elasticsearch is not a relational db and there are no joins but I would like to find the best way to achieve this goal.

When I search for a post I need to provide the user who published the post alongside the post source.

One possible solution would be to denormalize user data at index time but username could change quite often and I'm not sure about using updateByQuery for string modifications ( Can the username be used for script injection?)

The second solution I was looking for is the parent/child solution but I can not find any way to include the parent in each child but sending a get request for each parent id.

Check out inner_hits, that might help you.


Using has_child and inner hits I lose the score of each child if a parent has more than one child.
What I want to achieve is a normal match query with normal scoring but I want to include in each child his parent

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