diff --git a/lib/Elastica/Type.php b/lib/Elastica/Type.php index fdd253a300..8e5825db1d 100644 --- a/lib/Elastica/Type.php +++ b/lib/Elastica/Type.php @@ -148,8 +148,10 @@ public function updateDocument($data, array $options = array()) throw new InvalidException('Document or Script id is not set'); } + $id = urlencode($data->getId()); + return $this->getIndex()->getClient()->updateDocument( - $data->getId(), + $id, $data, $this->getIndex()->getName(), $this->getName(), diff --git a/test/lib/Elastica/Test/TypeTest.php b/test/lib/Elastica/Test/TypeTest.php index badfb32bbd..89aeeb147d 100644 --- a/test/lib/Elastica/Test/TypeTest.php +++ b/test/lib/Elastica/Test/TypeTest.php @@ -565,6 +565,32 @@ public function testUpdateDocument() $this->assertEquals(3, $updatedDoc['counter'], "Counter was not incremented"); } + public function testUpdateDocumentWithIdForwardSlashes() + { + $client = $this->_getClient(); + $index = $client->getIndex('elastica_test'); + $type = $index->getType('update_type'); + $id = '/id/with/forward/slashes'; + $type->addDocument(new Document($id, array('name' => 'bruce wayne batman', 'counter' => 1))); + $newName = 'batman'; + + $document = new Document(); + $script = new Script( + "ctx._source.name = name; ctx._source.counter += count", + array( + 'name' => $newName, + 'count' => 2, + ), + null, + $id + ); + $script->setUpsert($document); + + $type->updateDocument($script, array('refresh' => true)); + $updatedDoc = $type->getDocument($id)->getData(); + $this->assertEquals($newName, $updatedDoc['name'], "Name was not updated"); + $this->assertEquals(3, $updatedDoc['counter'], "Counter was not incremented"); + } public function testUpdateDocumentWithParameter() { $client = $this->_getClient();