ScoutEngines\Elasticsearch\ElasticsearchEngine::delete PHP Method

delete() public method

Remove the given model from the index.
public delete ( Illuminate\Database\Eloquent\Collection $models ) : void
$models Illuminate\Database\Eloquent\Collection
return void
    public function delete($models)
    {
        $params['body'] = [];
        $models->each(function ($model) use(&$params) {
            $params['body'][] = ['delete' => ['_id' => $model->getKey(), '_index' => $this->index, '_type' => $model->searchableAs()]];
        });
        $this->elastic->bulk($params);
    }

Usage Example

 public function test_delete_removes_objects_to_index()
 {
     $client = Mockery::mock('Elasticsearch\\Client');
     $client->shouldReceive('bulk')->with(['body' => [['delete' => ['_id' => 1, '_index' => 'scout', '_type' => 'table']]]]);
     $engine = new ElasticsearchEngine($client, 'scout');
     $engine->delete(Collection::make([new ElasticsearchEngineTestModel()]));
 }