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
# File 'lib/estool/actions/index.rb', line 14

def format_options(data)
  params = {}
  data.each do |k, v|
    case k
    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



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

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



43
44
45
46
# File 'lib/estool/actions/index.rb', line 43

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