yiisoft / yii2-elasticsearch

Yii 2 Elasticsearch extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
427 stars 253 forks source link

For an existing record, delete it twice in a row. Immediately after t… #296

Closed hkui closed 3 years ago

hkui commented 3 years ago

For an existing record, delete it twice in a row. Immediately after the first deletion, 404 is returned for the second deletion

Q A
Is bugfix? yes
New feature? no
Breaks BC? no
Tests pass? yes
Fixed issues comma-separated list of tickets # fixed by the PR, if any

The code Below will repoer errors "yii\elasticsearch\ActiveRecord::deleteAll failed deleting records"

  //$this->model is a ActiveRecord instance
        $r1=$this->model->deleteAll(['id'=>1]);
        #sleep(2)
        $r2=$this->model->deleteAll(['id'=>1]);
        var_dump($r1);
        var_dump($r2);

Because you can still find the data when you query immediately after deletion

image

samdark commented 3 years ago

@beowulfenator would you please take a look?

beowulfenator commented 3 years ago

This is not an error, this is expected behavior of elasticsearch. An item is fully deleted after the corresponding shard is refreshed. See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html.

You're attempting to suppress errors that arise when trying to delete non-existent items.

Try

$r1 = $this->model->deleteAll(['id'=>1]);
$this->model->db->createCommand()->refreshIndex(($this->model)::index());
$r2 = $this->model->deleteAll(['id'=>1]);
var_dump($r1);
var_dump($r2);