yii\elasticsearch\ActiveRecord::updateAll PHP Method

updateAll() public static method

For example, to change the status to be 1 for all customers whose status is 2: ~~~ Customer::updateAll(['status' => 1], ['status' => 2]); ~~~
public static updateAll ( array $attributes, array $condition = [] ) : integer
$attributes array attribute values (name-value pairs) to be saved into the table
$condition array the conditions that will be passed to the `where()` method when building the query. Please refer to [[ActiveQuery::where()]] on how to specify this parameter.
return integer the number of rows updated
    public static function updateAll($attributes, $condition = [])
    {
        $primaryKeys = static::primaryKeysByCondition($condition);
        if (empty($primaryKeys)) {
            return 0;
        }
        $bulkCommand = static::getDb()->createBulkCommand(["index" => static::index(), "type" => static::type()]);
        foreach ($primaryKeys as $pk) {
            $bulkCommand->addAction(["update" => ["_id" => $pk]], ["doc" => $attributes]);
        }
        $response = $bulkCommand->execute();
        $n = 0;
        $errors = [];
        foreach ($response['items'] as $item) {
            if (isset($item['update']['status']) && $item['update']['status'] == 200) {
                $n++;
            } else {
                $errors[] = $item['update'];
            }
        }
        if (!empty($errors) || isset($response['errors']) && $response['errors']) {
            throw new Exception(__METHOD__ . ' failed updating records.', $errors);
        }
        return $n;
    }