Rake Tasks

elastics:index:create

This rake task reads the configuration elastics.yml file with your custom mappings, merges it with the internally generated mapping and routings, and creates the index. It is important to run this task when you start a new app, specially if you use the elastics-models gem with parent/child relationships (see elastics-models).

Environment variables

This task can be customized with the following environment variables:

  • FORCE Deletes the existing indices before running. Default false.
  • INDEX String representing one or a comma-separated list of indices to create. Default: Elastics::Configuration.variables[:index].
elastics:index:delete

Deletes the index/indices.

Environment variables

This task can be customized with the following environment variables:

  • INDEX String representing one or a comma-separated list of indices to delete. Default: Elastics::Configuration.variables[:index].
elastics:import

This is a specific task provided by the elastics-models gem.

It imports all or any of the models of your application.

Environment variables

This task can be customized with the following environment variables:

  • FORCE Deletes the existing indices before reindexing. Default false.
  • BATCH_SIZE The batch size used to retrieve the records and bulk post to the elasticsearch server. Default 500.
  • TIMEOUT The HTTP-client timeout. Default 60 for this task. (it is usually 5 for regular queries as set in Configuration.http_client_options[:timeout]). You might need a higher timeout if you raise the BATCH_SIZE.
  • IMPORT_OPTIONS A query string like string representing a hash of options to be used with the find_in_batches methods.
  • MODELS String representing one or a comma-separated list of model classes. Default Elastics::Configuration.elastics_models.
elastics:admin:dump

This is a specific task provided by the elastics-admin gem.

It dumps the index/indices to a dump file, which can be feed to the elastics:admin:load task to reload/restore the index.

Environment variables

This task can be customized with the following environment variables:

  • FILE The path to the dump file. Default: './elastics.dump'
  • INDEX String representing one or a comma-separated list of indices to dump. Default: Elastics::Configuration.variables[:index]
  • TYPE String representing one or a comma-separated list of types to dump. Default: Elastics::Configuration.variables[:type]
  • SCROLL elasticsearch option for the scan_type search performed to retrieve the documents. Default: '5m'
  • SIZE Represents the number of documents per shard dumped at a time. Default: 50
  • VERBOSE Prints info during the process. Default: true
elastics:admin:load

This is a specific task provided by the elastics-admin gem.

It reload/restore the index by loading a dump file (produced by the the elastics:admin:dump)

Notice: It loads the data into the original index name. If you want to reload the data into another index, you must set the INDEX_MAP variable.

Environment variables

This task can be customized with the following environment variables:

  • FILE The path to the dump file. Default: './elastics.dump'
  • BATCH_SIZE The document batch size used to import the dump file to the elasticsearch server. Default 500.
  • INDEX_MAP The index rename map (example: -m=mydumpedindexname:myloadedindexname,a:b).
  • TIMEOUT The HTTP-client timeout. Default 60 for this task. (it is usually 5 for regular queries as set in Configuration.http_client_options[:timeout]). You might need a higher timeout if you raise the BATCH_SIZE.
  • VERBOSE Prints info during the process. Default: true