Module: Elastics::Tasks::Mappings
- Included in:
- Elastics::Tasks
- Defined in:
- lib/elastics/tasks/mappings.rb
Instance Attribute Summary collapse
-
#mappings_path ⇒ Object
writeonly
Sets the attribute mappings_path.
Instance Method Summary collapse
- #index_for_type(type) ⇒ Object
- #indices ⇒ Object
- #mappings ⇒ Object
- #mappings_paths ⇒ Object
-
#put_mappings(options = {}) ⇒ Object
Mappings to put can be filtered with ‘:indices` & `:types` arrays.
- #types ⇒ Object
Instance Attribute Details
#mappings_path=(value) ⇒ Object (writeonly)
Sets the attribute mappings_path
4 5 6 |
# File 'lib/elastics/tasks/mappings.rb', line 4 def mappings_path=(value) @mappings_path = value end |
Instance Method Details
#index_for_type(type) ⇒ Object
41 42 43 |
# File 'lib/elastics/tasks/mappings.rb', line 41 def index_for_type(type) config[:index] || type end |
#indices ⇒ Object
37 38 39 |
# File 'lib/elastics/tasks/mappings.rb', line 37 def indices @indices ||= (super + types.map { |type| index_for_type(type) }).uniq end |
#mappings ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/elastics/tasks/mappings.rb', line 24 def mappings @mappings ||= mappings_paths.map { |path| Dir["#{path}/*.yml"] }. flatten.sort. each_with_object({}) do |file, hash| name = File.basename file, '.yml' hash[name] = YAML.load_file(file) end end |
#mappings_paths ⇒ Object
6 7 8 |
# File 'lib/elastics/tasks/mappings.rb', line 6 def mappings_paths @mappings_paths ||= base_paths.map { |x| File.join x, 'mappings' } end |
#put_mappings(options = {}) ⇒ Object
Mappings to put can be filtered with ‘:indices` & `:types` arrays.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/elastics/tasks/mappings.rb', line 11 def put_mappings( = {}) version = .fetch :version, :current filter = [:indices].try!(:map, &:to_s) each_filtered(types, [:types]) do |type| index = index_for_type(type) next if filter && !filter.include?(index) versioned_index = versioned_index_name(index, version) log "Putting mapping #{index}/#{type} (#{versioned_index}/#{type})" client.put_mapping index: versioned_index, type: type, data: mappings[type] end end |
#types ⇒ Object
33 34 35 |
# File 'lib/elastics/tasks/mappings.rb', line 33 def types @types ||= mappings.keys end |