我有兩個文檔類型,在一個父子關係:麻煩與has_parent查詢function_score
"myParent" : {
"properties" : {
"weight" : {
"type" : "double"
}
}
}
"myChild" : {
"_parent" : {
"type" : "myParent"
},
"_routing" : {
"required" : true
}
}
的weight
字段是要被用於定製的得分/排序。該查詢直接對母文件按預期工作:
{
"query" : {
"function_score" : {
"script_score" : {
"script" : "_score * doc['weight'].value"
}
}
}
}
然而,試圖用一個has_parent
查詢子文檔做類似的進球時,我得到一個錯誤:
{
"query" : {
"has_parent" : {
"query" : {
"function_score" : {
"script_score" : {
"script" : "_score * doc['weight'].value"
}
}
},
"parent_type" : "myParent",
"score_type" : "score"
}
}
}
的錯誤是:
QueryPhaseExecutionException[[myIndex][3]: query[filtered(ParentQuery[myParent](filtered(function score (ConstantScore(:),function=script[_score * doc['weight'].value], params [null]))->cache(_type:myParent)))->cache(_type:myChild)],from[0],size[10]: Query Failed [failed to execute context rewrite]]; nested: ElasticSearchIllegalArgumentException[No field found for [weight] in mapping with types [myChild]];
好像而不是應用打分函數給家長,那麼它的結果傳遞給孩子,ES嘗試應用評分向孩子發生作用,導致錯誤。
如果我沒有使用score
作爲score_type
,則不會發生錯誤,雖然結果得分然後全部爲1.0
,如記錄。
我在這裏錯過了什麼?我如何通過基於父字段的自定義評分來查詢這些子文檔?
@DrTech耐心,伊阿古,耐心;) –
:D /我耐心地等待 – DrTech