I have two types of document in parent-child relation:
"myParent" : { "properties" : { "weight" : { "type" : "double" } } } "myChild" : { "_parent" : { "type" : "myParent" }, "_routing" : { "required" : true } }
The weight field should be used for custom counting / sorting. This request directly against parent documents works as intended:
{ "query" : { "function_score" : { "script_score" : { "script" : "_score * doc['weight'].value" } } } }
However, when I try to do a similar count for child documents with a has_parent request has_parent I get an error:
{ "query" : { "has_parent" : { "query" : { "function_score" : { "script_score" : { "script" : "_score * doc['weight'].value" } } }, "parent_type" : "myParent", "score_type" : "score" } } }
Error:
QueryPhaseExecutionException [[myIndex] [3]: query [filtered (ParentQuery [myParent] (filtered (function rating (ConstantScore (:), function = script [_ score * doc ['weight']. Value], params [null]) ) → cache (_type: myParent))) → cache (_type: myChild)], from [0], size [10]: Query Failed [context correspondence failed]]; inested: ElasticSearchIllegalArgumentException [Field not found for [weight] when matching with types [myChild]];
It seems that instead of applying the count function to the parent element and then passing its result to the child element, ES tries to apply the count function to itself, causing an error.
If I do not use score for score_type , an error does not occur, although the score is then 1.0 , as described.
What am I missing here? How can I request these child documents with a custom count based on the parent field?
source share