docs: def index(models=None, name=None, force=False, keep=False):
      '''
      Initialize or rebuild the search index
  
      Models to reindex can optionally be specified as arguments.
      If not, all models are reindexed.
      '''
      index_name = name or default_index_name()
  
      doc_types_names = [m.__name__.lower() for m in adapter_catalog.keys()]
      models = [model.lower().rstrip('s') for model in (models or [])]
      for model in models:
          if model not in doc_types_names:
              log.error('Unknown model %s', model)
              sys.exit(-1)
  
      log.info('Initiliazing index "{0}"'.format(index_name))
      if es.indices.exists(index_name):
          if IS_TTY and not force:
              msg = 'Index {0} will be deleted, are you sure?'
              click.confirm(msg.format(index_name), abort=True)
          es.indices.delete(index_name)
  
      es.initialize(index_name)
  
      with handle_error(index_name, keep):
  
          disable_refresh(index_name)
          for adapter in iter_adapters():
              if not models or adapter.doc_type().lower() in models:
                  index_model(index_name, adapter)
              else:
                  log.info('Copying {0} objects to the new index'.format(
                           adapter.model.__name__))
                  # Need upgrade to Elasticsearch-py 5.0.0 to write:
                  # es.reindex({
                  #     'source': {'index': es.index_name, 'type': adapter.doc_type()},
                  #     'dest': {'index': index_name}
                  # })
                  #
                  # http://elasticsearch-py.readthedocs.io/en/master/api.html#elasticsearch.Elasticsearch.reindex
                  # This method (introduced in Elasticsearch 2.3 but only in Elasticsearch-py 5.0.0)
                  # triggers a server-side documents copy.
                  # Instead we use this helper for meant for backward compatibility
                  # but with poor performance as copy is client-side (scan+bulk)
                  es_reindex(es.client, es.index_name, index_name, scan_kwargs={
                      'doc_type': adapter.doc_type()
                  })
  
          enable_refresh(index_name)
      # At this step, we don't want error handler to delete the index
      # in case of error
      set_alias(index_name, delete=not keep)