From 85ad4f58bf210ee28045deace473de175f9a6506 Mon Sep 17 00:00:00 2001 From: Claudio Pinto Date: Thu, 15 Nov 2018 11:38:20 +0000 Subject: [PATCH] Fixed scoutKey not used when generating elastic search key --- src/Engines/ElasticSearchEngine.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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