如题目,我的请求json如下:
{
"size": 0,
"aggs": {
"car_type": {
"terms": {
"field": "screenName",
"size": 10
},
"aggs": {
"active_num": {
"terms": {
"field": "activeNum",
"size": 10
},
"aggs": {
"active_count": {
"value_count": {
"field": "activeNum"
}
},
"result" : {
"bucket_script": {
"buckets_path": {
"count1" : "car_type>all_count",
"count2" : "active_count"
},
"script": "params.count2/params.count1"
}
}
}
},
"all_count": {
"value_count": {
"field": "activeNum"
}
}
}
}
}
}
我想在result
中使用car_type>all_count
这样使用的话会报错如下:
No aggregation found for path [car_type>all_count]
找不到这个path
,看了官网确实不能这么实用,然后我更换了使用的位置,请求如下:
{
"size": 0,
"aggs": {
"car_type": {
"terms": {
"field": "screenName",
"size": 10
},
"aggs": {
"active_num": {
"terms": {
"field": "activeNum",
"size": 10
},
"aggs": {
"active_count": {
"value_count": {
"field": "activeNum"
}
}
}
},
"all_count": {
"value_count": {
"field": "activeNum"
}
},
"result" : {
"bucket_script": {
"buckets_path": {
"count1" : "all_count",
"count2" : "active_num>active_count"
},
"script": "params.count2/params.count1"
}
}
}
}
}
}
这样的话就有了另一个错,因为active_count
的值会有多个,报错如下:
buckets_path must reference either a number value or a single value numeric metric aggregation, got: java.lang.Object[]
我该怎样才能达到我的目的呢?