这是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
}
}
]
}
}
]
}
}
}
```
感谢。应该是我之前描述得不清楚,json中,`tags`和`ct`这样的字段,我们是不能预告知道其字段的,则`buckets`会有现在这样多层嵌套,最多可以到6层以上,现在的问题就是不能用预先定义ct、Tags这几个结构来读取数据,必须要一层一层读interface{}
#7
更多评论