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

Returns a new instance of Commands.



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

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



99
100
101
# File 'lib/ej/commands.rb', line 99

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

#aliasesObject



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

def aliases
  puts_with_format(@indices.aliases)
end

#bulkObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ej/commands.rb', line 122

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



71
72
73
74
75
76
77
78
79
# File 'lib/ej/commands.rb', line 71

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

#count(query = ) ⇒ Object



54
55
56
# File 'lib/ej/commands.rb', line 54

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

#create_aliasesObject



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

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

#deleteObject



205
206
207
208
# File 'lib/ej/commands.rb', line 205

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

#delete_templateObject



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

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

#distinct(term) ⇒ Object



61
62
63
# File 'lib/ej/commands.rb', line 61

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

#dumpObject



84
85
86
# File 'lib/ej/commands.rb', line 84

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

#facet(term) ⇒ Object



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

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

#healthObject



138
139
140
# File 'lib/ej/commands.rb', line 138

def health
  puts_with_format(@cluster.health)
end

#indicesObject



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

def indices
  puts_with_format(@indices.indices)
end

#mappingObject



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

def mapping
  puts_with_format(@indices.mapping)
end

#maxObject



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

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

#minObject



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

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

#nodes_infoObject



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

def nodes_info
  puts_with_format @nodes.nodes_info
end

#nodes_statsObject



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

def nodes_stats
  puts_with_format @nodes.nodes_stats
end

#not_analyzedObject



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

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

#put_routingObject



178
179
180
181
# File 'lib/ej/commands.rb', line 178

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



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

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

#recoveryObject



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

def recovery
  @indices.recovery
end

#refreshObject



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

def refresh
  puts_with_format(@indices.refresh)
end

#search(query = ) ⇒ Object



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

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



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

def settings
  puts_with_format(@indices.settings)
end

#stateObject



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

def state
  puts_with_format(@cluster.state)
end

#statsObject



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

def stats
  puts_with_format(@indices.stats)
end

#templateObject



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

def template
  puts_with_format(@indices.template)
end

#versionObject



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

def version
  puts VERSION
end

#warmerObject



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

def warmer
  puts_with_format(@indices.warmer)
end