Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling of doc => string data in Bulk Action #575

Merged
merged 3 commits into from
Mar 25, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES

2014-03-25
- Allow json string as data srouce for Bulk\Action on update
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the pull request id at the end of the line.


2014-03-20
- Allow for request params in delete by query calls #573

Expand Down
2 changes: 2 additions & 0 deletions lib/Elastica/Bulk/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public function toString()
$source = $this->getSource();
if (is_string($source)) {
$string.= $source;
} elseif (is_array($source) && array_key_exists('doc', $source) && is_string($source['doc'])) {
$string.= '{"doc": ' . $source['doc'] . '}';
} else {
$string.= json_encode($source, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
Expand Down
18 changes: 18 additions & 0 deletions test/lib/Elastica/Test/BulkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,24 @@ public function testUpdate()
$doc = $type->getDocument(6);
$this->assertEquals('test', $doc->test);

//test updating via document with json string as data
$doc3 = $type->createDocument(2);
$bulk = new Bulk($client);
$bulk->setType($type);
$doc3->setData('{"name" : "Paul it is"}');
$updateAction = new \Elastica\Bulk\Action\UpdateDocument($doc3);
$bulk->addAction($updateAction);
$response = $bulk->send();

$this->assertTrue($response->isOk());
$this->assertFalse($response->hasError());

$index->refresh();

$doc = $type->getDocument(2);
$docData = $doc->getData();
$this->assertEquals('Paul it is', $docData['name']);

$index->delete();
}

Expand Down