diff --git a/changes.txt b/changes.txt index d2fa0c2e9a..8e1f81ac7e 100644 --- a/changes.txt +++ b/changes.txt @@ -5,7 +5,7 @@ CHANGES - Add testing on PHP 7 on Travis #826 2015-05-06 -- Add Elastica\Util::reindex function by scan and bulk way http://www.elastic.co/guide/en/elasticsearch/guide/master/reindex.html #829 #931 +- Add Elastica\Util::copy function by scan and bulk way http://www.elastic.co/guide/en/elasticsearch/guide/master/reindex.html. Note: This was first called reindex #829 #931 ##836 2015-04-23 - Allow bool in Query::setSource function #818 http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html diff --git a/lib/Elastica/Util.php b/lib/Elastica/Util.php index f5b875e0c0..591a38d12d 100644 --- a/lib/Elastica/Util.php +++ b/lib/Elastica/Util.php @@ -190,13 +190,13 @@ public static function convertRequestToCurlCommand(Request $request) /** * Copy all data from and old index to a new index * - * @param \Elastica\Index $newIndex * @param \Elastica\Index $oldIndex + * @param \Elastica\Index $newIndex * @param string $expiryTime * @param int $sizePerShard - * @return bool + * @return \Elastica\Index The new index object */ - public static function reindex(Index $newIndex, Index $oldIndex, $expiryTime = '1m', $sizePerShard = 1000) + public static function copy(Index $oldIndex, Index $newIndex, $expiryTime = '1m', $sizePerShard = 1000) { $search = new Search($oldIndex->getClient()); $bulk = new Bulk($newIndex->getClient()); @@ -217,8 +217,9 @@ public static function reindex(Index $newIndex, Index $oldIndex, $expiryTime = ' $bulk->addActions($actions); $bulk->send(); } + $newIndex->refresh(); - return true; + return $newIndex; } } diff --git a/test/lib/Elastica/Test/UtilTest.php b/test/lib/Elastica/Test/UtilTest.php index 610f4df914..35cb7fabe9 100644 --- a/test/lib/Elastica/Test/UtilTest.php +++ b/test/lib/Elastica/Test/UtilTest.php @@ -119,7 +119,7 @@ public function testConvertDateTimeObjectWithoutTimezone() $this->assertEquals($convertedString, $date); } - public function testReindex() + public function testCopy() { $client = $this->_getClient(); $oldIndex = $client->getIndex("elastica_test_reindex"); @@ -153,13 +153,13 @@ public function testReindex() $oldIndex->refresh(); - $this->assertTrue(Util::reindex($newIndex, $oldIndex ,"1m",1)); + $this->assertInstanceOf('Elastica\Index', Util::copy($oldIndex, $newIndex,"1m",1)); $newCount = $newIndex->count(); $this->assertEquals(8, $newCount); } - public function testReindexFail() + public function testCopyFail() { $client = $this->_getClient(); @@ -179,7 +179,7 @@ public function testReindexFail() $newIndex2->delete(); try { - Util::reindex($newIndex, $oldIndex); + Util::copy($oldIndex, $newIndex); $this->fail('New Index should not exist'); } catch (ResponseException $e) { $this->assertContains('IndexMissingException', $e->getMessage());