Skip to content

Commit

Permalink
Merge pull request #836 from ruflin/reindex-refactoring-to-copy
Browse files Browse the repository at this point in the history
Rename reindex function to copy and switch params
  • Loading branch information
ruflin committed May 11, 2015
2 parents 6eb6a31 + b8b7463 commit 96e87c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion changes.txt
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lib/Elastica/Util.php
Expand Up @@ -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());
Expand All @@ -217,8 +217,9 @@ public static function reindex(Index $newIndex, Index $oldIndex, $expiryTime = '
$bulk->addActions($actions);
$bulk->send();
}

$newIndex->refresh();

return true;
return $newIndex;
}
}
8 changes: 4 additions & 4 deletions test/lib/Elastica/Test/UtilTest.php
Expand Up @@ -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");
Expand Down Expand Up @@ -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();

Expand All @@ -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());
Expand Down

0 comments on commit 96e87c8

Please sign in to comment.