def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
      return if algolia_without_auto_index_scope
      algolia_configurations.each do |options, settings|
        next if algolia_indexing_disabled?(options)
        next if options[:slave] || options[:replica]

        # fetch the master settings
        master_index = algolia_ensure_init(options, settings)
        master_settings = master_index.get_settings rescue {} # if master doesn't exist yet
        master_settings.merge!(JSON.parse(settings.to_settings.to_json)) # convert symbols to strings

        # remove the replicas of the temporary index
        master_settings.delete :slaves
        master_settings.delete 'slaves'
        master_settings.delete :replicas
        master_settings.delete 'replicas'

        # init temporary index
        index_name = algolia_index_name(options)
        tmp_options = options.merge({ :index_name => "#{index_name}.tmp" })
        tmp_options.delete(:per_environment) # already included in the temporary index_name
        tmp_settings = settings.dup
        tmp_index = algolia_ensure_init(tmp_options, tmp_settings, master_settings)

        algolia_find_in_batches(batch_size) do |group|
          if algolia_conditional_index?(tmp_options)
            # select only indexable objects
            group = group.select { |o| algolia_indexable?(o, tmp_options) }
          end
          objects = group.map { |o| tmp_settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o, tmp_options) }
          tmp_index.save_objects(objects)
        end

        move_task = SafeIndex.move_index(tmp_index.name, index_name)
        master_index.wait_task(move_task["taskID"]) if synchronous || options[:synchronous]
      end
      nil
    end
def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
      return if algolia_without_auto_index_scope
      algolia_configurations.each do |options, settings|
        next if algolia_indexing_disabled?(options)
        next if options[:slave] || options[:replica]

        # fetch the master settings
        master_index = algolia_ensure_init(options, settings)
        master_settings = master_index.get_settings rescue {} # if master doesn't exist yet
        master_settings.merge!(JSON.parse(settings.to_settings.to_json)) # convert symbols to strings

        # remove the replicas of the temporary index
        master_settings.delete :slaves
        master_settings.delete 'slaves'
        master_settings.delete :replicas
        master_settings.delete 'replicas'

        # init temporary index
        index_name = algolia_index_name(options)
        tmp_options = options.merge({ :index_name => "#{index_name}.tmp" })
        tmp_options.delete(:per_environment) # already included in the temporary index_name
        tmp_settings = settings.dup
        tmp_index = algolia_ensure_init(tmp_options, tmp_settings, master_settings)

        algolia_find_in_batches(batch_size) do |group|
          if algolia_conditional_index?(tmp_options)
            # select only indexable objects
            group = group.select { |o| algolia_indexable?(o, tmp_options) }
          end
          objects = group.map { |o| tmp_settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o, tmp_options) }
          tmp_index.save_objects(objects)
        end

        move_task = SafeIndex.move_index(tmp_index.name, index_name)
        master_index.wait_task(move_task["taskID"]) if synchronous || options[:synchronous]
      end
      nil
    end
reindex whole database using a extra temporary index + move operation