private function reindexAtomically(Index $index, array $algoliaRecords)
    {
        $temporaryIndexName = 'tmp_' . $index->indexName;

        $temporaryIndex = $this->initIndex($temporaryIndexName);
        $temporaryIndex->addObjects($algoliaRecords);

        $settings = $index->getSettings();

        // Temporary index overrides all the settings on the main one.
        // So we need to set the original settings on the temporary one before atomically moving the index.
        $temporaryIndex->setSettings($settings);

        return $this->moveIndex($temporaryIndexName, $index->indexName);
    }