Skip to content

Commit

Permalink
Set index for bulk operations globally (#705)
Browse files Browse the repository at this point in the history
* Set index for bulk operations globally. Fixes #701

(cherry picked from commit 7c6968f)

* corrected bulk tests
  • Loading branch information
Christoph Singer authored and saimaz committed Nov 14, 2016
1 parent e8379cb commit e2f0b81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Service/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function commit(array $params = [])
{
if (!empty($this->bulkQueries)) {
$bulkQueries = array_merge($this->bulkQueries, $this->bulkParams);

$bulkQueries['index']['_index'] = $this->getIndexName();
$this->eventDispatcher->dispatch(
Events::PRE_COMMIT,
new CommitEvent($this->getCommitMode(), $bulkQueries)
Expand Down Expand Up @@ -432,7 +432,6 @@ public function bulk($operation, $type, array $query)
$this->bulkQueries['body'][] = [
$operation => array_filter(
[
'_index' => $this->getIndexName(),
'_type' => $type,
'_id' => isset($query['_id']) ? $query['_id'] : null,
'_ttl' => isset($query['_ttl']) ? $query['_ttl'] : null,
Expand Down
30 changes: 24 additions & 6 deletions Tests/Unit/Service/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ public function getTestBulkData()
return [
'index_document' => [
'expected' => [
'index' => [
'_index' => 'test',
],
'body' => [
[
'index' => ['_index' => 'test', '_type' => 'product'],
'index' => ['_type' => 'product'],
],
[
'field1' => 'value1',
Expand All @@ -48,9 +51,12 @@ public function getTestBulkData()
],
'index_document_with_id' => [
'expected' => [
'index' => [
'_index' => 'test',
],
'body' => [
[
'index' => ['_index' => 'test', '_type' => 'product', '_id' => 'foo'],
'index' => ['_type' => 'product', '_id' => 'foo'],
],
[
'field1' => 'value1',
Expand All @@ -70,9 +76,12 @@ public function getTestBulkData()
],
'create_document' => [
'expected' => [
'index' => [
'_index' => 'test',
],
'body' => [
[
'create' => ['_index' => 'test', '_type' => 'product'],
'create' => ['_type' => 'product'],
],
[
'field1' => 'value1',
Expand All @@ -91,9 +100,12 @@ public function getTestBulkData()
],
'delete_document' => [
'expected' => [
'index' => [
'_index' => 'test',
],
'body' => [
[
'delete' => ['_index' => 'test', '_type' => 'product', '_id' => 'foo'],
'delete' => ['_type' => 'product', '_id' => 'foo'],
],
],
],
Expand All @@ -109,9 +121,12 @@ public function getTestBulkData()
],
'update_doc' => [
'expected' => [
'index' => [
'_index' => 'test',
],
'body' => [
[
'update' => ['_index' => 'test', '_type' => 'product'],
'update' => ['_type' => 'product'],
],
[
'doc' => ['title' => 'Sample'],
Expand All @@ -132,9 +147,12 @@ public function getTestBulkData()
],
'update_script' => [
'expected' => [
'index' => [
'_index' => 'test',
],
'body' => [
[
'update' => ['_index' => 'test', '_type' => 'product'],
'update' => ['_type' => 'product'],
],
[
'script' => 'ctx._source.counter += count',
Expand Down

0 comments on commit e2f0b81

Please sign in to comment.