/** * 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()); }
/** * @param ElasticIndex $oldIndex * @param ElasticIndex $newIndex */ private function moveDataBetweenIndices(ElasticIndex $oldIndex, ElasticIndex $newIndex) { CrossIndex::reindex($oldIndex, $newIndex); $newIndexEntity = new Index($newIndex->getName()); $this->entityManager->persist($newIndexEntity); $this->entityManager->flush($newIndexEntity); }