我正试图在laravel中访问Elasticquent聚合桶列表对象:
array:1 [▼ "group_by_law_year" => array:3 [▼
"doc_count_error_upper_bound" => 0
"sum_other_doc_count" => 0
"buckets" => array:2 [▼
0 => array:2 [▼
"key" => "2013"
"doc_count" => 2
]
1 => array:2 [▼
"key" => "2012"
"doc_count" => 1
]
] ] ]
我尝试过像$laws_y->getAggregations('group_by_law_year').get()
,但没有成功。有人有想法吗?
答案 0 :(得分:0)
getAggregations
将返回一个数组(如上面的输出所示),因此您只需要检索buckets
并迭代它们,如下所示:
$buckets = $laws_y->getAggregations()['group_by_law_year']['buckets'];
foreach ($buckets as $bucket){
echo $bucket['key'] . ' = ' . $bucket['doc_count'];
}