Pick latest child records of each parent and aggregate data

Hi Mark,

Thank you for your insight. We are planning to use database for storing frequent updates and sync to elastic later once a day.

This has led us to another problem

I want to know what would be my latest child record. I can use inner_hits with descending sort on update date stored in child (specify size as 1) to get the desired result.

Is it possible to filter these inner hits ? What I mean to say is that, lets say I have two child records
{ name:a , date: 2018-12-12} , {name:b,date:2018-12-13} having same parent. Inner hits with date sorting(desc) and size=1 will give me record {name:b, date:2018-12-13}. Is it possible to also search for name a in latest record? In plain English, it would be to find parent having latest child record containing name 'a' . For example, in the scenario which I gave earlier, since the latest record is {name:b, date:2018-12-13}, the parent would not appear in result.

Also does inner_hits has performance penalty? I read somewhere that it impact search result timings.