diff --git a/src/Engines/ElasticSearchEngine.php b/src/Engines/ElasticSearchEngine.php index 36dcc8c..9339913 100644 --- a/src/Engines/ElasticSearchEngine.php +++ b/src/Engines/ElasticSearchEngine.php @@ -57,7 +57,7 @@ public function update($models) function ($model) use (&$params) { $params['body'][] = [ 'update' => [ - '_id' => $model->getKey(), + '_id' => $this->getElasticKey($model), '_index' => $this->index, '_type' => $model->searchableAs(), ] @@ -85,7 +85,7 @@ public function delete($models) function ($model) use (&$params) { $params['body'][] = [ 'delete' => [ - '_id' => $model->getKey(), + '_id' => $this->getElasticKey($model), '_index' => $this->index, '_type' => $model->searchableAs(), ] @@ -257,7 +257,7 @@ protected function filters(Builder $builder) if ($builder instanceof \ScoutEngines\Elasticsearch\Builder) { return ($builder->toESDL()); } - + return collect($builder->wheres)->map( function ($value, $key) { if (is_array($value)) { @@ -288,4 +288,13 @@ function ($order) { } )->toArray(); } + + protected function getElasticKey($model) + { + if (method_exists($model, 'getScoutKey')) { + return $model->getScoutKey(); + } + + return $model->getKey(); + } } \ No newline at end of file