尝试在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 \"]并输入一个数字,一切正常。
答案 0 :(得分:2)
您正在使用bucket_script
,这是与Elasticsearch 2.0一起发布的pipeline aggregations的一部分。管道聚合适用于其他聚合而非文档,这就是为聚合提供doc
上下文的原因。
如果您想针对特定文档处理聚合,那么您可能希望改为使用scripted metric aggregation。