我正在使用弹性搜索5.5.1。我的要求是申请以下公式:( doc_count*100/10)以下数据集:
{
"took": 30,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 13,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by_botId": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1,
"doc_count": 9
},
{
"key": 3,
"doc_count": 4
}
]
}
}
}
我应该能够找到每个存储桶项目的解决方案。我不想将Java SDK用于此问题,因为要求仅使用弹性搜索REST API。
您可以使用bucket_script
聚合来为每个存储桶运行一个脚本:
"aggs": {
"group_by_botId": {
"terms": {
"field": "botId"
},
"aggs": {
"count": {
"bucket_script": {
"buckets_path": {
"doc_count" : "_count"
},
"script": "params.doc_count * 100 / 10"
}
}
}
}
}