yii\elasticsearch\Query::batch PHP Method

batch() public method

A batch query supports fetching data in batches, which can keep the memory usage under a limit. This method will return a BatchQueryResult object which implements the [[\Iterator]] interface and can be traversed to retrieve the data in batches. For example, php $query = (new Query)->from('user'); foreach ($query->batch() as $rows) { $rows is an array of 10 or fewer rows from user table } Batch size is determined by the limit setting (note that in scan mode batch limit is per shard).
Since: 2.0.4
public batch ( string $scrollWindow = '1m', Connection $db = null ) : BatchQueryResult
$scrollWindow string how long Elasticsearch should keep the search context alive, in [time units](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units)
$db Connection the database connection. If not set, the `elasticsearch` application component will be used.
return BatchQueryResult the batch query result. It implements the [[\Iterator]] interface and can be traversed to retrieve the data in batches.
    public function batch($scrollWindow = '1m', $db = null)
    {
        return Yii::createObject(['class' => BatchQueryResult::className(), 'query' => $this, 'scrollWindow' => $scrollWindow, 'db' => $db, 'each' => false]);
    }