Class: Metacrunch::Elasticsearch::IndexCreator
- Inherits:
-
Object
- Object
- Metacrunch::Elasticsearch::IndexCreator
- Includes:
- ClientFactory, OptionsHelpers
- Defined in:
- lib/metacrunch/elasticsearch/index_creator.rb
Instance Attribute Summary collapse
-
#default_mapping ⇒ Object
Returns the value of attribute default_mapping.
-
#delete_existing_index ⇒ Object
Returns the value of attribute delete_existing_index.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #call(items = []) ⇒ Object
-
#initialize(options = {}) ⇒ IndexCreator
constructor
A new instance of IndexCreator.
Methods included from OptionsHelpers
#extract_options!, #normalize_options!
Methods included from ClientFactory
Constructor Details
#initialize(options = {}) ⇒ IndexCreator
Returns a new instance of IndexCreator.
15 16 17 18 19 |
# File 'lib/metacrunch/elasticsearch/index_creator.rb', line 15 def initialize( = {}) (@client_args = ).deep_symbolize_keys! (@client_args, :_client_options_, :default_mapping, :delete_existing_index, :logger, :number_of_shards, :number_of_replicas, :settings) raise ArgumentError.new("You have to supply an index name!") if @client_args[:index].blank? end |
Instance Attribute Details
#default_mapping ⇒ Object
Returns the value of attribute default_mapping.
10 11 12 |
# File 'lib/metacrunch/elasticsearch/index_creator.rb', line 10 def default_mapping @default_mapping end |
#delete_existing_index ⇒ Object
Returns the value of attribute delete_existing_index.
11 12 13 |
# File 'lib/metacrunch/elasticsearch/index_creator.rb', line 11 def delete_existing_index @delete_existing_index end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/metacrunch/elasticsearch/index_creator.rb', line 12 def logger @logger end |
#settings ⇒ Object
Returns the value of attribute settings.
13 14 15 |
# File 'lib/metacrunch/elasticsearch/index_creator.rb', line 13 def settings @settings end |
Instance Method Details
#call(items = []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/metacrunch/elasticsearch/index_creator.rb', line 21 def call(items = []) client = client_factory logger = @logger if client.indices.exists?(@client_args) if @delete_existing_index == true client.indices.delete(@client_args) log_index_deleted(logger, @client_args[:index], client) if logger elsif @delete_existing_index == false return else raise Metacrunch::Elasticsearch::IndexAlreadyExistsError end end client.indices.create(@client_args.merge( { body: { number_of_shards: @number_of_shards, number_of_replicas: @number_of_replicas, settings: @settings }.compact } )) log_index_created(logger, @client_args[:index], client) if logger if @default_mapping client.indices.put_mapping( @client_args.merge( type: "_default_", body: { _default_: @default_mapping } ) ) end end |