Class: Metacrunch::Elasticsearch::Cli::DumpMetadata

Inherits:
Command
  • Object
show all
Defined in:
lib/metacrunch/elasticsearch/cli/dump_metadata.rb

Instance Method Summary collapse

Instance Method Details

#callObject Also known as: perform



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/metacrunch/elasticsearch/cli/dump_metadata.rb', line 5

def call
  [:mappings, :settings].each do |_element|
    _filename_option = "#{_element}_filename"

    if options[_filename_option].present?
      options["dump_#{_element}"] = true
    end

    if options[_filename_option] == _filename_option
      options.delete(_filename_option)
    end

    if options["dump_#{_element}"]
      if filename = options["#{_element}_filename"]
        File.write(filename, format(send(_element), format_from_filename(filename)))
      else
        puts send(_element)
      end
    end
  end

  if !options[:dump_mapping] && !options[:dump_settings]
    puts format(settings.merge(mappings), options[:format])
    
    if options[:format] == :yaml
      $stderr.puts "\n        You have requested to dump settings and mapping into YAML. Please keep in mind\n        that if you are trying to create an index with both, settings and mapping, this\n        request has to be JSON formatted. Nevertheless you can create the index with YAML\n        settings and put a YAML formatted mapping afterwards.\n\n        https://github.com/elastic/elasticsearch/issues/1755\n\n      MESSAGE\n    end\n  end\nend\n".strip_heredoc