elasticsearch\ActiveRecord delete()

delete() public method

Deletes the table row corresponding to this active record.

This method performs the following steps in order:

  1. call beforeDelete(). If the method returns false, it will skip the rest of the steps;
  2. delete the record from the database;
  3. call afterDelete().

In the above step 1 and 3, events named EVENT_BEFORE_DELETE and EVENT_AFTER_DELETE will be raised by the corresponding methods.

public integer|boolean delete ( $options = [] )
$options array

Options given in this parameter are passed to elasticsearch as request URI parameters. These are among others:

  • routing define shard placement of this record.
  • parent by giving the primaryKey of another record this defines a parent-child relation
  • timeout timeout waiting for a shard to become available.
  • replication the replication type for the delete/index operation (sync or async).
  • consistency the write consistency of the index/delete operation.
  • refresh refresh the relevant primary and replica shards (not the whole index) immediately after the operation occurs, so that the updated document appears in search results immediately.

Please refer to the elasticsearch documentation for more details on these options.

The following parameters are Yii specific:

  • optimistic_locking set this to true to enable optimistic locking, avoid updating when the record has changed since it has been loaded from the database. Yii will set the version parameter to the value stored in \yii\elasticsearch\version. See the elasticsearch documentation for details.

    Make sure the record has been fetched with a \yii\elasticsearch\version before. This is only the case for records fetched via get() and mget() by default. For normal queries, the _version field has to be fetched explicitly.

return integer|boolean

The number of rows deleted, or false if the deletion is unsuccessful for some reason. Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.

throws yii\db\StaleObjectException

if optimistic locking is enabled and the data being deleted is outdated.

throws yii\elasticsearch\Exception

in case delete failed.

doc_Yii
2016-10-30 17:01:20
Comments
Leave a Comment

Please login to continue.