gpt4 book ai didi

elasticsearch - 在 Elasticsearch 查询的内联脚本中使用聚合函数

转载 作者:行者123 更新时间:2023-12-03 00:15:46 26 4
gpt4 key购买 nike

我试图在 flex 搜索查询的script_fields部分中使用聚合函数的结果,但是我们无法在查询的此部分中引用聚合结果。理想情况下,我想将聚合字段“MaxProductCount”乘以2以计算“ProductScore”,如下所示:

{
"filter": {
"bool": {
"must": [
{
"fquery": {
"query": {
"query_string": {
"query": "id = 6436"
}
}
}
}
]
}
},
"aggregations" : {
"MaxProductCount" : { "max" : { "script" : "doc['total'].value" } }
},
"script_fields" : {
"ProductScore" : {
"script" : "aggregations['MaxProductCount'].value * 2"
}
}
}

错误响应为:
"reason" : {
"type" : "script_exception",
"reason" : "failed to run inline script [aggregations['MaxProductCount'].value] using lang [groovy]",
"caused_by" : {
"type" : "missing_property_exception",
"reason" : "No such property: aggregations for class: 1b1aa6e761136e0f4c14b7223dd6639071c21bc4"
}

有谁知道在script_fields部分中是否可以引用聚合结果?

谢谢。

最佳答案

简短的答案是您不能将聚合嵌入脚本字段中。脚本字段是一个合成字段,它是基于对该文档的字段值进行的一些计算为每个文档创建的,而聚合是在整个选定文档集上计算的。因此,您不能将两者混在一起。

关于elasticsearch - 在 Elasticsearch 查询的内联脚本中使用聚合函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36032082/

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