Skip to content

Commit

Permalink
Need to add Routing meta-field to be able to use join datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
burakcakirel authored and matchish committed Mar 14, 2020
1 parent 6683500 commit e07909b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/ElasticSearch/Params/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function delete($docs): void
}

/**
* TODO: Add ability to extend payload without modifying the class
*
* @return array
*/
public function toArray(): array
Expand All @@ -47,6 +49,7 @@ function ($payload, $model) {
'_index' => $model->searchableAs(),
'_id' => $model->getScoutKey(),
'_type' => '_doc',
'routing' => false === empty($model->routing) ? $model->routing : $model->getScoutKey(),
],
];

Expand All @@ -67,6 +70,7 @@ function ($payload, $model) {
'_index' => $model->searchableAs(),
'_id' => $model->getScoutKey(),
'_type' => '_doc',
'routing' => false === empty($model->routing) ? $model->routing : $model->getScoutKey(),
],
];

Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/ElasticSearch/Params/BulkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test_delete()
$params = $bulk->toArray();

$this->assertEquals([
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 2]]],
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 2, 'routing' => 2]]],
], $params);
}

Expand All @@ -31,7 +31,7 @@ public function test_delete_with_custom_key_name()
$params = $bulk->toArray();

$this->assertEquals([
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout']]],
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout', 'routing' => 'Scout']]],
], $params);
}

Expand All @@ -45,7 +45,7 @@ public function test_index()

$this->assertEquals([
'body' => [
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2]],
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2, 'routing' => 2]],
['title' => 'Scout', 'id' => 2, '__class_name' => 'App\Product'],
],
], $params);
Expand All @@ -62,7 +62,7 @@ public function test_index_with_custom_key_name()

$this->assertEquals([
'body' => [
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout']],
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout', 'routing' => 'Scout']],
['title' => 'Scout', 'id' => 2, '__class_name' => 'App\Product'],
],
], $params);
Expand All @@ -78,7 +78,7 @@ public function test_push_soft_delete_meta_data()
$params = $bulk->toArray();
$this->assertEquals([
'body' => [
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2]],
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2, 'routing' => 2]],
['title' => 'Scout', '__soft_deleted' => 0, 'id' => 2, '__class_name' => 'App\Product'],
],
], $params);
Expand Down

0 comments on commit e07909b

Please sign in to comment.