Sort by NestedDocsProvider.childDocs always returns all results. The situation is not recommended. If the final results themselves do not contain elements contained in the filter, then they should not sort by these values. As a result, the sorted items do not match and the calculated values.
JUnit Test, Wildflay
The childQuery query contains a correctly found question, but wastage selection does not follow the filter. I think "childDocs" should only contain documents that meet the filter conditions, but now also includes those that do not. There is a similar object in Elasticserch, it is possible that they solved this problem, you can copy the solution.