gpt4 book ai didi

elasticsearch - 编写Elasticsearch 2.1脚本没有这样的属性:doc

转载 作者:行者123 更新时间:2023-12-02 23:00:49 26 4
gpt4 key购买 nike

尝试在ES JSON请求中执行脚本时遇到问题

要求:

POST _search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
},
"aggs": {
"bucket_histogram": {
"histogram": {
"field": "dayTime",
"interval": 10
},
"aggs": {
"get_average": {
"avg": {
"field": "value"
}
},
"check-threshold": {
"bucket_script": {
"buckets_path": {
"averageValue": "get_average"
},
"script": "averageValue - doc[\"thresholdValue\"].value"
}
}
}
}
}
}

但是我得到这个错误而不是返回值
    {
"error": {
"root_cause": [],
"type": "reduce_search_phase_exception",
"reason": "[reduce] ",
"phase": "fetch",
"grouped": true,
"failed_shards": [],
"caused_by": {
"type": "groovy_script_execution_exception",
"reason": "failed to run inline script [averageValue - doc[\"thresholdValue\"].value] using lang [groovy]",
"caused_by": {
"type": "missing_property_exception",
"reason": "No such property: doc for class: 7dcca7d142ac809a7192625d43d95bde9883c434"
}
}
},
"status": 503
}

但是,如果我删除doc [\“thresholdValue \”]并输入数字,则一切正常。

最佳答案

您正在使用bucket_script,它是随Elasticsearch 2.0发布的pipeline aggregations的一部分。管道聚合与其他聚合(而不是文档)一起工作,这就是为什么doc上下文不提供给聚合的原因。

如果要针对特定​​文档处理聚合,则可能需要scripted metric aggregation

关于elasticsearch - 编写Elasticsearch 2.1脚本没有这样的属性:doc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34638910/

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