copy() public static method

Copies type mappings and documents from an old index to a new index.
See also: Elastica\Tool\CrossIndex::reindex()
public static copy ( Index $oldIndex, Index $newIndex, array $options = [] ) : Index
$oldIndex Elastica\Index
$newIndex Elastica\Index
$options array keys: CrossIndex::OPTION_* constants
return Elastica\Index The new index object
 /**
  * Test default copy.
  *
  * @group functional
  */
 public function testCopy()
 {
     $oldIndex = $this->_createIndex(null, true, 2);
     $newIndex = $this->_createIndex(null, true, 2);
     $oldType = $oldIndex->getType('copy_test');
     $oldMapping = array('name' => array('type' => 'string', 'store' => true));
     $oldType->setMapping($oldMapping);
     $docs = $this->_addDocs($oldType, 10);
     // mapping
     $this->assertInstanceOf('Elastica\\Index', CrossIndex::copy($oldIndex, $newIndex));
     $newMapping = $newIndex->getType('copy_test')->getMapping();
     if (!isset($newMapping['copy_test']['properties']['name'])) {
         $this->fail('could not request new mapping');
     }
     $this->assertEquals($oldMapping['name'], $newMapping['copy_test']['properties']['name']);
     // document copy
     $this->assertEquals(10, $newIndex->count());
     $newIndex->deleteDocuments($docs);
     // ignore mapping
     $ignoredType = $oldIndex->getType('copy_test_1');
     $this->_addDocs($ignoredType, 10);
     CrossIndex::copy($oldIndex, $newIndex, array(CrossIndex::OPTION_TYPE => $oldType));
     $this->assertFalse($newIndex->getType($ignoredType->getName())->exists());
     $this->assertEquals(10, $newIndex->count());
 }