Child聚合中的Elasticsearch Bucket_script

时间:2018-06-15 01:07:41

标签: elasticsearch

我正在尝试在Elasticsearch中建模和查询系统。我正在实施的内容包括活动和广告系列,其中广告系列是加入类型结构中的一组事件,每个事件都有自己的状态。

广告系列A:       事件1:完成       活动2:待定       活动3:完成

现在,使用 bucket_script ,我不知道按广告系列分组的每个事件状态的百分比:

广告系列A.     完成:66.66%     待定:33.33%

我正在尝试使用以下查询:

{
"query": {

    "has_child": {
        "type": "event",
        "query": {
            "match_all": {}
        }
    }
},
"aggs": {
    "events": {
        "children": {
            "type": "event"
        },
        "aggs": {
            "totalDone": {
                "sum": {
                    "field": "done"
                }
            },
            "totalPending": {
                "sum": {
                    "field": "pending"
                }
            },
            "totalCalls": {
                "value_count": {
                    "field": "_id"
                }
            },

            "totalCallPercentageDone": {
                "bucket_script": {
                    "buckets_path": {
                        "done": "totalDone",
                        "total":"totalCalls"
                    },
                    "script": "(params.done*100)/total"
                }
            },

            "totalCallPercentagePending": {
                "bucket_script": {
                    "buckets_path": {
                        "pending": "totalPending",
                        "total":"totalCalls"
                    },
                    "script": "(params.pending*100)/total"
                }
            }

        }
    }
}

}

但我总是得到:

{
"error": {
    "root_cause": [],
    "type": "search_phase_execution_exception",
    "reason": "",
    "phase": "fetch",
    "grouped": true,
    "failed_shards": [],
    "caused_by": {
        "type": "class_cast_exception",
        "reason": "org.elasticsearch.join.aggregations.InternalChildren cannot be cast to org.elasticsearch.search.aggregations.InternalMultiBucketAggregation"
    }
},
"status": 503

}

是否可以在子聚合中使用Bucket Script?

0 个答案:

没有答案