gpt4 book ai didi

elasticsearch - 包含脚本化 function_score 的 has_parent 查询出现问题

转载 作者:行者123 更新时间:2023-11-29 02:54:02 26 4
gpt4 key购买 nike

我有两种文档类型,处于父子关系中:

"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,如文件所示。

我在这里错过了什么?如何使用基于父字段的自定义评分查询这些子文档?

最佳答案

我认为这是一个错误:它使用 myChild 映射作为默认上下文,即使您在 has_parent 查询中也是如此。但我不确定修复这个错误有多容易。

但是,您可以通过在完整字段名称中包含 type 名称来解决此问题:

curl -XGET "http://localhost:9200/t/myChild/_search" -d'
{
"query": {
"has_parent": {
"query": {
"function_score": {
"script_score": {
"script": "_score * doc[\"myParent.weight\"].value"
}
}
},
"parent_type": "myParent",
"score_type": "score"
}
}
}'

我已经打开了一个问题,看看我们是否可以解决这个问题 #4914

关于elasticsearch - 包含脚本化 function_score 的 has_parent 查询出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21289149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com