You usually do not instantiate BatchQueryResult directly. Instead, you obtain it by calling [[Query::batch()]] or [[Query::each()]]. Because BatchQueryResult implements the [[\Iterator]] interface, you can iterate it to obtain a batch of data in each iteration. Batch size is determined by the [[Query::$limit]] setting. [[Query::$offset]] setting is ignored. New batches will be obtained until the server runs out of results. If [[Query::$orderBy]] parameter is not set, batches will be processed using the highly efficient "scan" mode. In this case, [[Query::$limit]] setting determines batch size per shard. See elasticsearch guide for more information. Example: php $query = (new Query)->from('user'); foreach ($query->batch() as $i => $users) { $users represents the rows in the $i-th batch } foreach ($query->each() as $user) { }
Since: 2.0.4
Author: Konstantin Sirotkin (beowulfenator@gmail.com)
Inheritance: extends yii\base\Object, implements Iterator
Beispiel #1
0
 /**
  * Starts a batch query and retrieves data row by row.
  * This method is similar to [[batch()]] except that in each iteration of the result,
  * only one row of data is returned. For example,
  *
  * ```php
  * $query = (new Query)->from('user');
  * foreach ($query->each() as $row) {
  * }
  * ```
  *
  * @param string $scrollWindow 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)
  * @param Connection $db 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.
  * @since 2.0.4
  */
 public function each($scrollWindow = '1m', $db = null)
 {
     return Yii::createObject(['class' => BatchQueryResult::className(), 'query' => $this, 'scrollWindow' => $scrollWindow, 'db' => $db, 'each' => true]);
 }