Class: Desi::IndexManager
- Inherits:
-
Object
- Object
- Desi::IndexManager
- Defined in:
- lib/desi/index_manager.rb
Overview
Performs some simple index-related operations on a local or distance Elastic Search cluster
Instance Method Summary collapse
-
#delete!(pattern) ⇒ void
Delete all indices matching the specified pattern.
-
#empty!(pattern) ⇒ void
Empty (remove all records) from indices matching the specified pattern.
-
#initialize(opts = {}) ⇒ void
constructor
Initializes a Desi::IndexManager instance.
-
#list(pattern = '.*') ⇒ Array<String>
List index names for the specified cluster.
Constructor Details
#initialize(opts = {}) ⇒ void
The :http_client_factory
should return an instance that responds to #get and #delete
Initializes a Desi::IndexManager instance
26 27 28 29 30 31 |
# File 'lib/desi/index_manager.rb', line 26 def initialize(opts = {}) @host = to_uri(opts.fetch(:host, 'http://127.0.0.1:9200')) @verbose = opts[:verbose] @outputter = opts.fetch(:outputter, Kernel) @client = opts.fetch(:http_client_factory, Desi::HttpClient).new(@host) end |
Instance Method Details
#delete!(pattern) ⇒ void
No confirmation is needed, so beware!
This method will also output its result on STDOUT if @verbose is true
This method returns an undefined value.
Delete all indices matching the specified pattern
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/desi/index_manager.rb', line 74 def delete!(pattern) warn "You must provide a pattern" and exit if pattern.nil? @outputter.puts "The following indices from host #{@host} are now deleted" if @verbose indices(Regexp.new(pattern)).each do |index| @client.delete("/#{index}") @outputter.puts " * #{index}" if @verbose end end |
#empty!(pattern) ⇒ void
No confirmation is needed, so beware!
This method will also output its result on STDOUT if @verbose is true
This method returns an undefined value.
Empty (remove all records) from indices matching the specified pattern
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/desi/index_manager.rb', line 99 def empty!(pattern) warn "You must provide a pattern" and exit if pattern.nil? @outputter.puts "The following indices from host #{@host} are now emptied" if @verbose indices(Regexp.new(pattern)).each do |index| @client.delete("/#{index}/_query?q=*") @outputter.puts " * #{index}" if @verbose end end |
#list(pattern = '.*') ⇒ Array<String>
This method will also output its result on STDOUT if @verbose is true
List index names for the specified cluster
You can restrict the list using a regular expression pattern. (The default pattern being /.*/, all releases will be returned if you do not specify anything.)
50 51 52 53 54 55 56 57 58 |
# File 'lib/desi/index_manager.rb', line 50 def list(pattern = '.*') pattern = Regexp.new(pattern || '.*') @outputter.puts "Indices from host #{@host} matching the pattern #{pattern.inspect}\n\n" if @verbose list = indices(pattern).sort list.each {|i| @outputter.puts i } if @verbose list end |