我想要统计的是country_code 出现的次数,通过yii2的ElasticSearch扩展,上面的例子满足我的需要。业务场景:在fecify商城中,使用elasticSearch搜索,进行aggregate group操作,代码如下:
public function actionCountry(){
$size = 5000;
$name = 'country_code';
$type = 'terms';
$options = [
'field' => 'country_code',
'size' => $size,
];
$data = WholeCountryData::find()
//->limit(5000)
//->offset(0)
->asArray()
->addAgg($name, $type, $options)
->createCommand()
->search();
$agg_data = $data['aggregations'];
$buckets = $agg_data['country_code']['buckets'];
//var_dump($agg_data);exit;
$country_code_arr = \yii\helpers\BaseArrayHelper::getColumn($buckets,'key');
var_dump($country_code_arr);
}
相关文章
暂无评论...