/**
  * Exports es index to provided file.
  *
  * @param Manager         $manager
  * @param string          $filename
  * @param int             $chunkSize
  * @param OutputInterface $output
  */
 public function exportIndex(Manager $manager, $filename, $chunkSize, OutputInterface $output)
 {
     $types = $manager->getTypesMapping();
     $repo = $manager->getRepository($types);
     $results = $this->getResults($repo, $chunkSize);
     if (class_exists('\\Symfony\\Component\\Console\\Helper\\ProgressBar')) {
         $progress = new ProgressBar($output, $results->getTotalCount());
         $progress->setRedrawFrequency(100);
         $progress->start();
     } else {
         $progress = new ProgressHelper();
         $progress->setRedrawFrequency(100);
         $progress->start($output, $results->getTotalCount());
     }
     $metadata = ['count' => $results->getTotalCount(), 'date' => date(\DateTime::ISO8601)];
     $writer = $this->getWriter($this->getFilePath($filename), $metadata);
     foreach ($results as $data) {
         $writer->push(array_intersect_key($data, array_flip(['_id', '_type', '_source'])));
         $progress->advance();
     }
     $writer->finalize();
     $progress->finish();
     $output->writeln('');
 }