Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from cfpinto/fix-scout-key-not-used-in-elastic
Browse files Browse the repository at this point in the history
Fixed scoutKey not used when generating elastic search key
  • Loading branch information
cfpinto authored Nov 15, 2018
2 parents 5fa4d57 + 85ad4f5 commit 829a9a0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Engines/ElasticSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]
Expand Down Expand Up @@ -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(),
]
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -288,4 +288,13 @@ function ($order) {
}
)->toArray();
}

protected function getElasticKey($model)
{
if (method_exists($model, 'getScoutKey')) {
return $model->getScoutKey();
}

return $model->getKey();
}
}

0 comments on commit 829a9a0

Please sign in to comment.