Skip to content

Commit

Permalink
Remove copy function for release to not have BC breaks afterwards
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed May 13, 2015
1 parent 49017b3 commit d4fa023
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 105 deletions.
3 changes: 0 additions & 3 deletions changes.txt
Expand Up @@ -5,9 +5,6 @@ CHANGES
- Update elasticsearch dependency to elasticsearch 1.5.2 https://www.elastic.co/downloads/past-releases/elasticsearch-1-5-2 #834
- Add testing on PHP 7 on Travis #826

2015-05-06
- 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
- Fix empty bool query to act as match all query #817
Expand Down
35 changes: 0 additions & 35 deletions lib/Elastica/Util.php
Expand Up @@ -186,39 +186,4 @@ public static function convertRequestToCurlCommand(Request $request)

return $message;
}

/**
* Copy all data from and old index to a new index
*
* @param \Elastica\Index $oldIndex
* @param \Elastica\Index $newIndex
* @param string $expiryTime
* @param int $sizePerShard
* @return \Elastica\Index The new index object
*/
public static function copy(Index $oldIndex, Index $newIndex, $expiryTime = '1m', $sizePerShard = 1000)
{
$search = new Search($oldIndex->getClient());
$bulk = new Bulk($newIndex->getClient());
$bulk->setIndex($newIndex);

$search->addIndex($oldIndex);
$scanAndScroll = new ScanAndScroll($search, $expiryTime, $sizePerShard);

foreach ($scanAndScroll as $resultSet) {
$data = $resultSet->getResponse()->getData();
$actions = array();
foreach ($data['hits']['hits'] as $d) {
$meta = array('_index' => $newIndex->getName() , '_type' => $d['_type'], '_id' => $d['_id']);
$actions[] = new Action(Action::OP_TYPE_INDEX, $meta ,$d['_source']);
}
//$actions = new Bulk\Action();
$bulk->addActions($actions);
$bulk->send();
}

$newIndex->refresh();

return $newIndex;
}
}
67 changes: 0 additions & 67 deletions test/lib/Elastica/Test/UtilTest.php
Expand Up @@ -118,71 +118,4 @@ public function testConvertDateTimeObjectWithoutTimezone()

$this->assertEquals($convertedString, $date);
}

public function testCopy()
{
$client = $this->_getClient();
$oldIndex = $client->getIndex("elastica_test_reindex");
$oldIndex->create(array(
'number_of_shards' => 4,
'number_of_replicas' => 1,
),true);

$newIndex = $client->getIndex("elastica_test_reindex_v2");
$newIndex->create(array(
'number_of_shards' => 4,
'number_of_replicas' => 1,
),true);

$type1 = $oldIndex->getType("test1");
$type2 = $oldIndex->getType("test2");

$documents1[] = $type1->createDocument(1, array('name' => 'Xwei1'));
$documents1[] = $type1->createDocument(2, array('name' => 'Xwei2'));
$documents1[] = $type1->createDocument(3, array('name' => 'Xwei3'));
$documents1[] = $type1->createDocument(4, array('name' => 'Xwei4'));

$documents2[] = $type2->createDocument(1, array('name' => 'Xwei5'));
$documents2[] = $type2->createDocument(2, array('name' => 'Xwei6'));
$documents2[] = $type2->createDocument(3, array('name' => 'Xwei7'));
$documents2[] = $type2->createDocument(4, array('name' => 'Xwei8'));

$type1->addDocuments($documents1);
$type2->addDocuments($documents2);

$oldIndex->refresh();


$this->assertInstanceOf('Elastica\Index', Util::copy($oldIndex, $newIndex,"1m",1));

$newCount = $newIndex->count();
$this->assertEquals(8, $newCount);
}

public function testCopyFail()
{
$client = $this->_getClient();

$oldIndex = $client->getIndex("elastica_test_reindex");
$oldIndex->create(array(
'number_of_shards' => 4,
'number_of_replicas' => 1,
), true);

$newIndex = $client->getIndex("elastica_test_reindex_v2");
$newIndex->create(array(
'number_of_shards' => 4,
'number_of_replicas' => 1,
), true);

$newIndex2 = $client->getIndex("elastica_test_reindex_v2");
$newIndex2->delete();

try {
Util::copy($oldIndex, $newIndex);
$this->fail('New Index should not exist');
} catch (ResponseException $e) {
$this->assertContains('IndexMissingException', $e->getMessage());
}
}
}

0 comments on commit d4fa023

Please sign in to comment.