yii\elasticsearch\ActiveRecord::deleteAll PHP Method

deleteAll() public static method

WARNING: If you do not specify any condition, this method will delete ALL rows in the table. For example, to delete all customers whose status is 3: ~~~ Customer::deleteAll(['status' => 3]); ~~~
public static deleteAll ( array $condition = [] ) : integer
$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 deleted
    public static function deleteAll($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->addDeleteAction($pk);
        }
        $response = $bulkCommand->execute();
        $n = 0;
        $errors = [];
        foreach ($response['items'] as $item) {
            if (isset($item['delete']['status']) && $item['delete']['status'] == 200) {
                if (isset($item['delete']['found']) && $item['delete']['found']) {
                    $n++;
                }
            } else {
                $errors[] = $item['delete'];
            }
        }
        if (!empty($errors) || isset($response['errors']) && $response['errors']) {
            throw new Exception(__METHOD__ . ' failed deleting records.', $errors);
        }
        return $n;
    }