From 6a2bcf5644a2503b18596c803217bf683ebbdbd2 Mon Sep 17 00:00:00 2001 From: Ruflin Date: Mon, 11 May 2015 13:00:06 +0200 Subject: [PATCH 1/3] Rename reindex function to copy and switch params --- lib/Elastica/Util.php | 9 +++++---- test/lib/Elastica/Test/UtilTest.php | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Elastica/Util.php b/lib/Elastica/Util.php index f5b875e0c0..22a349f5f0 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 Index */ - 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()); From efa67f42eba95019fbfacc5ce8697ff4d5ec9e55 Mon Sep 17 00:00:00 2001 From: Ruflin Date: Mon, 11 May 2015 13:08:18 +0200 Subject: [PATCH 2/3] Update changes notes to reflect this change --- changes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes.txt b/changes.txt index dd9beaa337..d5cea6b70b 100644 --- a/changes.txt +++ b/changes.txt @@ -4,7 +4,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 From b8b7463f21216c3a00e801e61c548e55460d14fa Mon Sep 17 00:00:00 2001 From: Ruflin Date: Mon, 11 May 2015 13:09:37 +0200 Subject: [PATCH 3/3] Improve return param doc for copy function --- lib/Elastica/Util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Elastica/Util.php b/lib/Elastica/Util.php index 22a349f5f0..591a38d12d 100644 --- a/lib/Elastica/Util.php +++ b/lib/Elastica/Util.php @@ -194,7 +194,7 @@ public static function convertRequestToCurlCommand(Request $request) * @param \Elastica\Index $newIndex * @param string $expiryTime * @param int $sizePerShard - * @return Index + * @return \Elastica\Index The new index object */ public static function copy(Index $oldIndex, Index $newIndex, $expiryTime = '1m', $sizePerShard = 1000) {