reindex() public static method

Reindex documents from an old index to a new index.
public static reindex ( 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 reindex type option.
  *
  * @group functional
  */
 public function testReindexTypeOption()
 {
     $oldIndex = $this->_createIndex('', true, 2);
     $type1 = $oldIndex->getType('crossIndexTest_1');
     $type2 = $oldIndex->getType('crossIndexTest_2');
     $docs1 = $this->_addDocs($type1, 10);
     $docs2 = $this->_addDocs($type2, 10);
     $newIndex = $this->_createIndex(null, true, 2);
     // \Elastica\Type
     CrossIndex::reindex($oldIndex, $newIndex, array(CrossIndex::OPTION_TYPE => $type1));
     $this->assertEquals(10, $newIndex->count());
     $newIndex->deleteDocuments($docs1);
     // string
     CrossIndex::reindex($oldIndex, $newIndex, array(CrossIndex::OPTION_TYPE => 'crossIndexTest_2'));
     $this->assertEquals(10, $newIndex->count());
     $newIndex->deleteDocuments($docs2);
     // array
     CrossIndex::reindex($oldIndex, $newIndex, array(CrossIndex::OPTION_TYPE => array('crossIndexTest_1', $type2)));
     $this->assertEquals(20, $newIndex->count());
 }
示例#2
0
 /**
  * @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);
 }