我曾经这样获得搜索结果:
$search->setQuery($query);
$results = $search->search()->getAggregations();
但是现在我正在使用滚动API:
$search->getQuery()->setSize(10000);
$scroll = new \Elastica\Scroll($search);
$results_arr = [];
foreach ($scroll as $scrollId => $resultSet) {
$results = $resultSet->getResults();
foreach($results as $r) {
$results_arr[] = $r->getHit();
}
}
问题是,如何结合使用滚动API和getAggregations()
函数,以使其无法获得匹配结果,而只能通过类似以下方式进行访问:
$results = $search->search()->getAggregations();
foreach($results['agg']['buckets'] as $k=>$v) {
...
}
如何在Elastica PHP中将滚动API与聚合结果结合在一起?