yii\elasticsearch\ActiveRecord::mget PHP Method

mget() public static method

Gets a list of records by its primary keys.
public static mget ( array $primaryKeys, array $options = [] ) : array
$primaryKeys array an array of primaryKey values
$options array options given in this parameter are passed to elasticsearch as request URI parameters. Please refer to the [elasticsearch documentation](http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html) for more details on these options.
return array The record instances, or empty array if nothing was found
    public static function mget(array $primaryKeys, $options = [])
    {
        if (empty($primaryKeys)) {
            return [];
        }
        if (count($primaryKeys) === 1) {
            $model = static::get(reset($primaryKeys));
            return $model === null ? [] : [$model];
        }
        $command = static::getDb()->createCommand();
        $result = $command->mget(static::index(), static::type(), $primaryKeys, $options);
        $models = [];
        foreach ($result['docs'] as $doc) {
            if ($doc['found']) {
                $model = static::instantiate($doc);
                static::populateRecord($model, $doc);
                $model->afterFind();
                $models[] = $model;
            }
        }
        return $models;
    }