桶脚本不工作 - elasticsearch 2.4.2
bucket script not working - elasticsearch 2.4.2
我尝试减去聚合
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"total_query_id": {
"sum": {
"field": "query_id"
}
},
"total_num_results": {
"sum": {
"field": "num_results"
}
},
"minus_value": {
"bucket_script": {
"buckets_path": {
"qid": "total_query_id",
"nrs": "total_num_results"
},
"script": "qid - nrs"
}
}
}
}
它抛出以下错误
"reason": "Invalid pipeline aggregation named [minus_value] of type [bucket_script]. Only sibling pipeline aggregations are allowed at the top level"
我来回移动了minus_value节点到aggs节点,但它并没有解决我的问题。
谁能帮我解决这个问题?
想法是管道聚合必须在父桶聚合上工作。
在你的例子中不是这种情况,所以你必须有一个父聚合。由于您有一个 match_all
查询,您可以尝试使用 global
桶聚合,然后将您的 3 个聚合嵌入其中,如下所示:
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"all": {
"global": {},
"aggs": {
"total_query_id": {
"sum": {
"field": "query_id"
}
},
"total_num_results": {
"sum": {
"field": "num_results"
}
},
"minus_value": {
"bucket_script": {
"buckets_path": {
"qid": "total_query_id",
"nrs": "total_num_results"
},
"script": "qid - nrs"
}
}
}
}
}
}
我尝试减去聚合
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"total_query_id": {
"sum": {
"field": "query_id"
}
},
"total_num_results": {
"sum": {
"field": "num_results"
}
},
"minus_value": {
"bucket_script": {
"buckets_path": {
"qid": "total_query_id",
"nrs": "total_num_results"
},
"script": "qid - nrs"
}
}
}
}
它抛出以下错误
"reason": "Invalid pipeline aggregation named [minus_value] of type [bucket_script]. Only sibling pipeline aggregations are allowed at the top level"
我来回移动了minus_value节点到aggs节点,但它并没有解决我的问题。
谁能帮我解决这个问题?
想法是管道聚合必须在父桶聚合上工作。
在你的例子中不是这种情况,所以你必须有一个父聚合。由于您有一个 match_all
查询,您可以尝试使用 global
桶聚合,然后将您的 3 个聚合嵌入其中,如下所示:
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"all": {
"global": {},
"aggs": {
"total_query_id": {
"sum": {
"field": "query_id"
}
},
"total_num_results": {
"sum": {
"field": "num_results"
}
},
"minus_value": {
"bucket_script": {
"buckets_path": {
"qid": "total_query_id",
"nrs": "total_num_results"
},
"script": "qid - nrs"
}
}
}
}
}
}