ToParentBlockJoinSortField does not handle missing values correctly
Description
I realised that as part of #15483 I'd made it impossible to set a missing value on ToParentBlockJoinSortField, so set about adding the functionality back in and adding some tests. This showed pretty quickly that the missing value functionality here doesn't really work in the way I'd expect.
The idea of this sort field is that you query parent documents, but order them by the 'best' value of their children. So a missing value should by rights be applied to a child document that doesn't have a value, as it's the children's values that are being used for ordering. However, what actually happens is that the missing value is used for parent documents that have either no children at all, or only children without sort values.
I think we should change this so that the missing value is propagated to the child sorters.
Version and environment details
No response
I would like to work on this. I plan to update ToParentBlockJoinSortField to ensure the missingValue is properly propagated down to the child document comparators. This will allow the missing value logic to apply to children before aggregation, rather than just to the parent.
I would also like to give it a try, I will take a look coming week, @ML-dev-crypto if you have already made some progress on it let me know.
First let's identify what we want to achieve here:
- Introduce configurable
missingValueone for parent level and one for child level, just like we have the two sorting order configurations. - Expand the "missing" scenarios to also be able to identify when a parent has children with missing values and use the child missing value there.
Missing value usage scenarios
- When a parent has no children, then we use the
parentMissingValue. - When a child does not have the sorting field, then we use the
childMissingValuewhen sorting the parent.