I have a parent-child relation where I want to do an aggregation on the parent, that sums up an integer property on the child items. The issue is that I have multiple children for each parent, and I am only interested in the first one for this particular sum.
Can this be done in pure ES aggregation fashion?
Using orders and orderlines as an example:
Order1
- OrderLine1
- price: 100
- OrderLine2
- price: 120
Order2
- OrderLine1
- price: 523
- OrderLine2
- price: 220
- OrderLine3
- price: 300
I would like to get the sum of price for all orders, but only taking the first child for each parent, so I would expect to get a sum of 100+523. It seems that the top_hits aggregation is not useful in this regard, but I could just be using it wrong. I do have other properties to sort on, if "first" needs to be relative to something.
Thank you in advance!