Rake Tasks

flex:index:create

This rake task reads the configuration flex.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 flex-models gem with parent/child relationships (see flex-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 list of indices to create. Default: Flex::Configuration.variables[:index].
$ rake flex:index:create INDEX=foo,bar
flex:index:delete

Deletes the index/indices.

Environment variables

This task can be customized with the following environment variables:

  • INDEX String representing one or a list of indices to delete. Default: Flex::Configuration.variables[:index].
flex:import

This is a specific task provided by the flex-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 1000.
  • TIMEOUT The HTTP-client timeout. Default 20 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.
  • CONFIG_FILE The configuration file. Default Flex::Configuration.config_file
  • MODELS Array like string representing a list of model classes. Default Flex::Configuration.flex_models.
$ rake flex:import MODELS=Foo,Bar
flex:admin:dump

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

It dumps the index/indices to a dump file, which can be feed to the flex: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: './flex.dump'
  • INDEX String representing one or a list of indices to dump. Default: Flex::Configuration.variables[:index]
  • TYPE String representing one or a list of types to dump. Default: Flex::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 informations during the process. Default: true
flex:admin:load

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

It reload/restore the index by loading a dump file (produced by the the flex: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: './flex.dump'
  • BATCH_SIZE The document batch size used to import the dump file to the elasticsearch server. Default 1000.
  • INDEX_MAP The index rename map (example: -m=dumped_index_name:loaded_index_name,a:b).
  • TIMEOUT The HTTP-client timeout. Default 20 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 informations during the process. Default: true