Class: Ej::Commands

Inherits:
Thor
  • Object
show all
Defined in:
lib/ej/commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Commands



23
24
25
26
27
28
29
30
31
# File 'lib/ej/commands.rb', line 23

def initialize(args = [], options = {}, config = {})
  super(args, options, config)
  @global_options = config[:shell].base.options
  values = Values.new(@global_options)
  @core = Ej::Core.new(values)
  @indices = Ej::Indices.new(values)
  @cluster = Ej::Cluster.new(values)
  @nodes = Ej::Nodes.new(values)
end

Instance Method Details

#aggsObject



105
106
107
# File 'lib/ej/commands.rb', line 105

def aggs
  puts_with_format(@core.aggs(options[:terms], options[:size], options[:query]))
end

#aliasesObject



149
150
151
# File 'lib/ej/commands.rb', line 149

def aliases
  puts_with_format(@indices.aliases)
end

#bulkObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ej/commands.rb', line 128

def bulk
  inputs = options[:inputs].empty? ? [STDIN] : options[:inputs]
  inputs.each do |key|
    buffer = (key.class == STDIN.class) ? STDIN.read : File.read(key)
    @core.bulk(
      options[:timestamp_key],
      options[:type],
      options[:add_timestamp],
      options[:id_keys],
      options[:index],
      Util.parse_json(buffer)
    )
  end
end

#copyObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ej/commands.rb', line 75

def copy
  @core.copy(
    options[:source],
    options[:dest],
    options[:query],
    options[:per],
    options[:scroll],
    options[:dest_index],
    options[:slice_max]
  )
end

#count(query = ) ⇒ Object



56
57
58
# File 'lib/ej/commands.rb', line 56

def count(query = options[:query])
  puts_with_format(@core.search(options[:type], query, 0, 0, false))
end

#create_aliasesObject



198
199
200
# File 'lib/ej/commands.rb', line 198

def create_aliases
  @indices.create_aliases(options[:alias], options[:indices])
end

#deleteObject



211
212
213
214
# File 'lib/ej/commands.rb', line 211

def delete
  query = options[:query] ? eval(options[:query]) : nil
  @indices.delete(options[:index], options[:type], query)
end

#delete_templateObject



218
219
220
# File 'lib/ej/commands.rb', line 218

def delete_template
  @indices.delete_template(options[:name])
end

#distinct(term) ⇒ Object



63
64
65
# File 'lib/ej/commands.rb', line 63

def distinct(term)
  puts_with_format(@core.distinct(term, options[:type], options[:query]))
end

#dumpObject



90
91
92
# File 'lib/ej/commands.rb', line 90

def dump
  @core.dump(options[:query], options[:per])
end

#facet(term) ⇒ Object



97
98
99
# File 'lib/ej/commands.rb', line 97

def facet(term)
  puts_with_format(@core.facet(term, options[:size], options[:query]))
end

#healthObject



144
145
146
# File 'lib/ej/commands.rb', line 144

def health
  puts_with_format(@cluster.health)
end

#indicesObject



159
160
161
# File 'lib/ej/commands.rb', line 159

def indices
  puts_with_format(@indices.indices)
end

#mappingObject



169
170
171
# File 'lib/ej/commands.rb', line 169

def mapping
  puts_with_format(@indices.mapping)
end

#maxObject



117
118
119
# File 'lib/ej/commands.rb', line 117

def max
  puts_with_format(@core.max(options[:term]))
end

#minObject



111
112
113
# File 'lib/ej/commands.rb', line 111

def min
  puts_with_format(@core.min(options[:term]))
end

#nodes_infoObject



243
244
245
# File 'lib/ej/commands.rb', line 243

def nodes_info
  puts_with_format @nodes.nodes_info
end

#nodes_statsObject



248
249
250
# File 'lib/ej/commands.rb', line 248

def nodes_stats
  puts_with_format @nodes.nodes_stats
end

#not_analyzedObject



174
175
176
177
178
# File 'lib/ej/commands.rb', line 174

def not_analyzed
  json = File.read(File.expand_path('../../../template/not_analyze_template.json', __FILE__))
  hash = JSON.parse(json)
  puts_with_format(@indices.put_template('ej_init', hash))
end

#put_routingObject



184
185
186
187
# File 'lib/ej/commands.rb', line 184

def put_routing
  body = { options[:type] => {"_routing"=>{"required"=>true, "path"=>options[:path]}}}
  puts_with_format(@indices.put_mapping(options[:index], options[:type], body))
end

#put_template(name) ⇒ Object



190
191
192
193
# File 'lib/ej/commands.rb', line 190

def put_template(name)
  hash = JSON.parse(STDIN.read)
  puts_with_format(@indices.put_template(name, hash))
end

#recoveryObject



203
204
205
# File 'lib/ej/commands.rb', line 203

def recovery
  @indices.recovery
end

#refreshObject



238
239
240
# File 'lib/ej/commands.rb', line 238

def refresh
  puts_with_format(@indices.refresh)
end

#search(query = ) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ej/commands.rb', line 41

def search(query = options[:query])
  puts_with_format(@core.search(options[:type],
                         query,
                         options[:size],
                         options[:from],
                         options[:meta],
                         nil,
                         options[:fields],
                         options[:sort]
                         ))
end

#settingsObject



228
229
230
# File 'lib/ej/commands.rb', line 228

def settings
  puts_with_format(@indices.settings)
end

#stateObject



154
155
156
# File 'lib/ej/commands.rb', line 154

def state
  puts_with_format(@cluster.state)
end

#statsObject



164
165
166
# File 'lib/ej/commands.rb', line 164

def stats
  puts_with_format(@indices.stats)
end

#templateObject



223
224
225
# File 'lib/ej/commands.rb', line 223

def template
  puts_with_format(@indices.template)
end

#versionObject



253
254
255
# File 'lib/ej/commands.rb', line 253

def version
  puts VERSION
end

#warmerObject



233
234
235
# File 'lib/ej/commands.rb', line 233

def warmer
  puts_with_format(@indices.warmer)
end