Class: Estool::Actions::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/estool/actions/index.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, options) ⇒ Index

Returns a new instance of Index.



8
9
10
11
12
# File 'lib/estool/actions/index.rb', line 8

def initialize(command, options)
  @cmd = command
  @data = options.except(:host, :port)
  @server = options.slice(:host, :port)
end

Instance Method Details

#format_options(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/estool/actions/index.rb', line 14

def format_options(data)
  params = {}
  data.each do |k, v|
    case k
    when :name
        params.merge!(index: v)
      when :update
        params.merge!(update_all_types: v)
      when :wait
        params.merge!(wait_for_active_shards: v)
      else
        params.merge!("#{k}": v)
    end
  end
  return params
end

#index(action, options, server) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/estool/actions/index.rb', line 31

def index(action, options, server)
  client = Estool::Connections.start_conn(server[:host], server[:port])
  Estool::Connections.test_conn(client)
  begin
    puts client.indices.send(action, options)
  rescue ArgumentError => args
      puts "
           #{args}
      Usage: 'estool index help #{action}' for more information
      "
      exit 1
  end
end

#runObject



45
46
47
48
# File 'lib/estool/actions/index.rb', line 45

def run
  params = format_options(@data)
  index(@cmd, params, @server)
end