这是elasticsearch的返回结构,aggregations中的user、tags、ct等都是不可预知的字段,要如何取出这些结构,并还原成一维map?
```json
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 3,
"failed": 0
},
"hits": {
"total": 22,
"max_score": 0,
"hits": []
},
"aggregations": {
"user": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "olivere",
"doc_count": 16,
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "golang",
"doc_count": 16,
"ct": {
"value": 16
}
},
{
"key": "elasticsearch",
"doc_count": 7,
"ct": {
"value": 7
}
}
]
}
},
{
"key": "sandrae",
"doc_count": 6,
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "cycling",
"doc_count": 6,
"ct": {
"value": 6
}
},
{
"key": "sports",
"doc_count": 6,
"ct": {
"value": 6
}
}
]
}
}
]
}
}
}
```
运行结果:
r = %#v {2 false {5 3 0} {{0 0 [{olivere 16 {0 0 [{golang 16 {16}} {elasticsearch 7 {7}}]}} {sandrae 6 {0 0 [{cycling 6
{6}} {sports 6 {6}}]}}]}}}
#6
更多评论