mirror of
https://github.com/d0zingcat/opensearch-orm.git
synced 2026-05-14 15:10:12 +00:00
18 lines
497 B
Python
18 lines
497 B
Python
def parse_aggregations(data: dict, depth: int = 1):
|
|
level = data.get(str(depth), None)
|
|
if level is None:
|
|
return
|
|
|
|
if 'buckets' in level:
|
|
result = {}
|
|
buckets = level['buckets']
|
|
for b in buckets:
|
|
key = b['key']
|
|
count = b['doc_count']
|
|
children = parse_aggregations(b, depth + 1)
|
|
result[key] = children if children else count
|
|
return result
|
|
else:
|
|
value = level['value']
|
|
return value
|