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
Defined Under Namespace
Classes: Index
Instance Method Summary collapse
-
#close!(pattern) ⇒ void
Close all indices matching the specified pattern.
-
#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
76 77 78 79 80 81 |
# File 'lib/desi/index_manager.rb', line 76 def initialize(opts = {}) @host = to_uri(opts.fetch(:host) { Desi.configuration.server }) @verbose = opts[:verbose] @outputter = opts.fetch(:outputter, Kernel) @client = opts.fetch(:http_client_factory, Desi::HttpClient).new(@host) end |
Instance Method Details
#close!(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.
Close all indices matching the specified pattern
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/desi/index_manager.rb', line 149 def close!(pattern) warn "You must provide a pattern" and exit if pattern.nil? @outputter.puts "The following indices from host #{@host} are now closed" if @verbose indices(Regexp.new(pattern)).each do |index| @client.post("/#{index}/_close") @outputter.puts " * #{index.inspect}" if @verbose end end |
#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
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/desi/index_manager.rb', line 124 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.inspect}" 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
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/desi/index_manager.rb', line 174 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.)
100 101 102 103 104 105 106 107 108 |
# File 'lib/desi/index_manager.rb', line 100 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.inspect } if @verbose list end |