src/Command/PopulateCommand.php
private function populateIndexType(OutputInterface $output, $index, $type, $reset, $options)
    {
        $event = new TypePopulateEvent($index, $type, $reset, $options);
        $this->dispatcher->dispatch(TypePopulateEvent::PRE_TYPE_POPULATE, $event);

        if ($event->isReset()) {
            $output->writeln(sprintf('<info>Resetting</info> <comment>%s/%s</comment>', $index, $type));
            $this->resetter->resetIndexType($index, $type);
        }

        $offset = 1 < $options['first_page'] ? ($options['first_page'] - 1) * $options['max_per_page'] : 0;
        $loggerClosure = ProgressClosureBuilder::build($output, 'Populating', $index, $type, $offset);

        $this->dispatcher->addListener(
            Events::ON_EXCEPTION,
            function(OnExceptionEvent $event) use ($loggerClosure) {
                $loggerClosure(
                    count($event->getObjects()),
                    $event->getPager()->getNbResults(),
                    sprintf('<error>%s</error>', $event->getException()->getMessage())
                );
            }
        );

        $this->dispatcher->addListener(
            Events::POST_INSERT_OBJECTS,
            function(PostInsertObjectsEvent $event) use ($loggerClosure) {
                $loggerClosure(count($event->getObjects()), $event->getPager()->getNbResults());
            }
        );

        $this->dispatcher->addListener(
            Events::POST_ASYNC_INSERT_OBJECTS,
            function(PostAsyncInsertObjectsEvent $event) use ($loggerClosure) {
                $loggerClosure($event->getObjectsCount(), $event->getPager()->getNbResults(), $event->getErrorMessage());
            }
        );

        if ($options['ignore_errors']) {
            $this->dispatcher->addListener(Events::ON_EXCEPTION, function(OnExceptionEvent $event) {
                if ($event->getException() instanceof BulkResponseException) {
                    $event->setIgnore(true);
                }
            });
        }

        $provider = $this->pagerProviderRegistry->getProvider($index, $type);

        $pager = $provider->provide($options);

        $options['indexName'] = $index;
        $options['typeName'] = $type;

        $this->pagerPersister->insert($pager, $options);

        $this->dispatcher->dispatch(TypePopulateEvent::POST_TYPE_POPULATE, $event);

        $this->refreshIndex($output, $index);
    }
private function populateIndexType(OutputInterface $output, $index, $type, $reset, $options)
    {
        $event = new TypePopulateEvent($index, $type, $reset, $options);
        $this->dispatcher->dispatch(TypePopulateEvent::PRE_TYPE_POPULATE, $event);

        if ($event->isReset()) {
            $output->writeln(sprintf('<info>Resetting</info> <comment>%s/%s</comment>', $index, $type));
            $this->resetter->resetIndexType($index, $type);
        }

        $offset = 1 < $options['first_page'] ? ($options['first_page'] - 1) * $options['max_per_page'] : 0;
        $loggerClosure = ProgressClosureBuilder::build($output, 'Populating', $index, $type, $offset);

        $this->dispatcher->addListener(
            Events::ON_EXCEPTION,
            function(OnExceptionEvent $event) use ($loggerClosure) {
                $loggerClosure(
                    count($event->getObjects()),
                    $event->getPager()->getNbResults(),
                    sprintf('<error>%s</error>', $event->getException()->getMessage())
                );
            }
        );

        $this->dispatcher->addListener(
            Events::POST_INSERT_OBJECTS,
            function(PostInsertObjectsEvent $event) use ($loggerClosure) {
                $loggerClosure(count($event->getObjects()), $event->getPager()->getNbResults());
            }
        );

        $this->dispatcher->addListener(
            Events::POST_ASYNC_INSERT_OBJECTS,
            function(PostAsyncInsertObjectsEvent $event) use ($loggerClosure) {
                $loggerClosure($event->getObjectsCount(), $event->getPager()->getNbResults(), $event->getErrorMessage());
            }
        );

        if ($options['ignore_errors']) {
            $this->dispatcher->addListener(Events::ON_EXCEPTION, function(OnExceptionEvent $event) {
                if ($event->getException() instanceof BulkResponseException) {
                    $event->setIgnore(true);
                }
            });
        }

        $provider = $this->pagerProviderRegistry->getProvider($index, $type);

        $pager = $provider->provide($options);

        $options['indexName'] = $index;
        $options['typeName'] = $type;

        $this->pagerPersister->insert($pager, $options);

        $this->dispatcher->dispatch(TypePopulateEvent::POST_TYPE_POPULATE, $event);

        $this->refreshIndex($output, $index);
    }
Deletes/remaps an index type, populates it, and refreshes the index.

@param OutputInterface $output
@param string          $index
@param string          $type
@param bool            $reset
@param array           $options