Skip to content

Commit 93a1d28

Browse files
committed
Merge pull request #575 from pentarim/master
handling of doc => string data in Bulk Action
2 parents 2f4dc04 + 71aeb72 commit 93a1d28

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ CHANGES
22
2014-03-24
33
- Added Filter\Indices #574
44

5+
2014-03-25
6+
- Allow json string as data srouce for Bulk\Action on update #575
7+
58
2014-03-20
69
- Allow for request params in delete by query calls #573
710

lib/Elastica/Bulk/Action.php

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ public function toString()
190190
$source = $this->getSource();
191191
if (is_string($source)) {
192192
$string.= $source;
193+
} elseif (is_array($source) && array_key_exists('doc', $source) && is_string($source['doc'])) {
194+
$string.= '{"doc": ' . $source['doc'] . '}';
193195
} else {
194196
$string.= json_encode($source, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
195197
}

test/lib/Elastica/Test/BulkTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,24 @@ public function testUpdate()
558558
$doc = $type->getDocument(6);
559559
$this->assertEquals('test', $doc->test);
560560

561+
//test updating via document with json string as data
562+
$doc3 = $type->createDocument(2);
563+
$bulk = new Bulk($client);
564+
$bulk->setType($type);
565+
$doc3->setData('{"name" : "Paul it is"}');
566+
$updateAction = new \Elastica\Bulk\Action\UpdateDocument($doc3);
567+
$bulk->addAction($updateAction);
568+
$response = $bulk->send();
569+
570+
$this->assertTrue($response->isOk());
571+
$this->assertFalse($response->hasError());
572+
573+
$index->refresh();
574+
575+
$doc = $type->getDocument(2);
576+
$docData = $doc->getData();
577+
$this->assertEquals('Paul it is', $docData['name']);
578+
561579
$index->delete();
562580
}
563581

0 commit comments

Comments
 (0)