Class: Eson::Client
- Inherits:
-
Object
- Object
- Eson::Client
- Defined in:
- lib/eson/client.rb
Constant Summary collapse
- DEFAULT_OPTS =
{ :server => 'http://127.0.0.1:9200', :plugins => [], :logger => nil, :default_index => "default" }
Instance Attribute Summary collapse
-
#auto_call ⇒ Object
Returns the value of attribute auto_call.
-
#default_index ⇒ Object
Returns the value of attribute default_index.
-
#index_name ⇒ Object
Returns the value of attribute index_name.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #[](index_name) ⇒ Object
- #aliases(args = {}, &block) ⇒ Object
- #analyze(args = {}) ⇒ Object
- #auth ⇒ Object
- #auth? ⇒ Boolean
- #bulk(args = {}, &block) ⇒ Object
- #clear_cache(args = {}) ⇒ Object
- #close_index(args = {}) ⇒ Object
- #count(args = {}) ⇒ Object
- #create_index(args = {}) ⇒ Object
- #delete(args = {}, immediate = auto_call) ⇒ Object
- #delete_by_query(args = {}, &block) ⇒ Object
- #delete_index(args = {}) ⇒ Object
- #delete_mapping(args = {}) ⇒ Object
- #delete_template(args = {}) ⇒ Object
- #exists?(args = {}) ⇒ Boolean
- #flush(args = {}) ⇒ Object
- #get(args = {}) ⇒ Object
- #get_mapping(args = {}) ⇒ Object
- #get_settings(args = {}) ⇒ Object
- #get_template(args = {}) ⇒ Object
- #health(args = {}) ⇒ Object
- #index(args = {}, immediate = auto_call) ⇒ Object
- #index_stats(args = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
TODO: allow multiple servers and pick them at random.
- #logger(logger) ⇒ Object
- #logger=(logger) ⇒ Object
- #mget(args = {}) ⇒ Object
- #more_like_this(args = {}) ⇒ Object
- #msearch(args = {}, &block) ⇒ Object
- #node ⇒ Object
- #nodes(args = {}) ⇒ Object
- #open_index(args = {}) ⇒ Object
- #optimize(args = {}) ⇒ Object
- #percolate(args = {}, &block) ⇒ Object
- #put_mapping(args = {}) ⇒ Object
- #put_template(args = {}) ⇒ Object
- #refresh(args = {}) ⇒ Object
- #search(args = {}, immediate = auto_call, &block) ⇒ Object (also: #query)
- #segments(args = {}) ⇒ Object
- #shutdown(args = {}) ⇒ Object
- #simple_search(args = {}) ⇒ Object
- #snapshot(args = {}) ⇒ Object
- #state(args = {}) ⇒ Object
- #stats(args = {}) ⇒ Object
- #status(args = {}) ⇒ Object
- #update_settings(args = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
TODO: allow multiple servers and pick them at random
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/eson/client.rb', line 19 def initialize(opts = {}) opts = DEFAULT_OPTS.merge(opts) self.server = opts[:server] self.default_index = opts[:default_index] self.protocol = opts[:protocol] || Eson::HTTP self.plugins = opts[:plugins] self.logger = opts[:logger] if opts[:auto_call].nil? self.auto_call = true else self.auto_call = opts[:auto_call] end self.opts = opts end |
Instance Attribute Details
#auto_call ⇒ Object
Returns the value of attribute auto_call.
9 10 11 |
# File 'lib/eson/client.rb', line 9 def auto_call @auto_call end |
#default_index ⇒ Object
Returns the value of attribute default_index.
5 6 7 |
# File 'lib/eson/client.rb', line 5 def default_index @default_index end |
#index_name ⇒ Object
Returns the value of attribute index_name.
4 5 6 |
# File 'lib/eson/client.rb', line 4 def index_name @index_name end |
#opts ⇒ Object
Returns the value of attribute opts.
8 9 10 |
# File 'lib/eson/client.rb', line 8 def opts @opts end |
#plugins ⇒ Object
Returns the value of attribute plugins.
7 8 9 |
# File 'lib/eson/client.rb', line 7 def plugins @plugins end |
#protocol ⇒ Object
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/eson/client.rb', line 6 def protocol @protocol end |
#server ⇒ Object
Returns the value of attribute server.
3 4 5 |
# File 'lib/eson/client.rb', line 3 def server @server end |
Instance Method Details
#[](index_name) ⇒ Object
59 60 61 62 63 |
# File 'lib/eson/client.rb', line 59 def [](index_name) c = self.clone c.index_name = index_name c end |
#aliases(args = {}, &block) ⇒ Object
142 143 144 |
# File 'lib/eson/client.rb', line 142 def aliases(args = {}, &block) request(protocol::Aliases, args, &block) end |
#analyze(args = {}) ⇒ Object
146 147 148 |
# File 'lib/eson/client.rb', line 146 def analyze(args = {}) request(protocol::Analyze, args) end |
#auth ⇒ Object
51 52 53 |
# File 'lib/eson/client.rb', line 51 def auth opts[:auth] end |
#auth? ⇒ Boolean
47 48 49 |
# File 'lib/eson/client.rb', line 47 def auth? !!opts[:auth] end |
#bulk(args = {}, &block) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/eson/client.rb', line 98 def bulk(args = {}, &block) if block_given? request(protocol::Bulk, args, &block) else request(protocol::Bulk, args, false) end end |
#clear_cache(args = {}) ⇒ Object
150 151 152 |
# File 'lib/eson/client.rb', line 150 def clear_cache(args = {}) request(protocol::ClearCache, args) end |
#close_index(args = {}) ⇒ Object
154 155 156 |
# File 'lib/eson/client.rb', line 154 def close_index(args = {}) request(protocol::CloseIndex, args) end |
#count(args = {}) ⇒ Object
90 91 92 |
# File 'lib/eson/client.rb', line 90 def count(args = {}) request(protocol::Count, args) end |
#create_index(args = {}) ⇒ Object
162 163 164 |
# File 'lib/eson/client.rb', line 162 def create_index(args = {}) request(protocol::CreateIndex, args) end |
#delete(args = {}, immediate = auto_call) ⇒ Object
69 70 71 |
# File 'lib/eson/client.rb', line 69 def delete(args = {}, immediate = auto_call) request(protocol::Delete, args, immediate) end |
#delete_by_query(args = {}, &block) ⇒ Object
114 115 116 |
# File 'lib/eson/client.rb', line 114 def delete_by_query(args = {}, &block) request(protocol::DeleteByQuery, args, &block) end |
#delete_index(args = {}) ⇒ Object
166 167 168 |
# File 'lib/eson/client.rb', line 166 def delete_index(args = {}) request(protocol::DeleteIndex, args) end |
#delete_mapping(args = {}) ⇒ Object
170 171 172 |
# File 'lib/eson/client.rb', line 170 def delete_mapping(args = {}) request(protocol::DeleteMapping, args) end |
#delete_template(args = {}) ⇒ Object
190 191 192 |
# File 'lib/eson/client.rb', line 190 def delete_template(args = {}) request(protocol::DeleteTemplate, args) end |
#exists?(args = {}) ⇒ Boolean
230 231 232 233 234 |
# File 'lib/eson/client.rb', line 230 def exists?(args = {}) request(protocol::IndexExists, args) rescue Eson::NotFoundError false end |
#flush(args = {}) ⇒ Object
202 203 204 |
# File 'lib/eson/client.rb', line 202 def flush(args = {}) request(protocol::Flush, args) end |
#get(args = {}) ⇒ Object
73 74 75 |
# File 'lib/eson/client.rb', line 73 def get(args = {}) request(protocol::Get, args) end |
#get_mapping(args = {}) ⇒ Object
174 175 176 |
# File 'lib/eson/client.rb', line 174 def get_mapping(args = {}) request(protocol::GetMapping, args) end |
#get_settings(args = {}) ⇒ Object
194 195 196 |
# File 'lib/eson/client.rb', line 194 def get_settings(args = {}) request(protocol::GetSettings, args) end |
#get_template(args = {}) ⇒ Object
186 187 188 |
# File 'lib/eson/client.rb', line 186 def get_template(args = {}) request(protocol::GetTemplate, args) end |
#health(args = {}) ⇒ Object
122 123 124 |
# File 'lib/eson/client.rb', line 122 def health(args = {}) request(protocol::Health, args) end |
#index(args = {}, immediate = auto_call) ⇒ Object
65 66 67 |
# File 'lib/eson/client.rb', line 65 def index(args = {}, immediate = auto_call) request(protocol::Index, args, immediate) end |
#index_stats(args = {}) ⇒ Object
222 223 224 |
# File 'lib/eson/client.rb', line 222 def index_stats(args = {}) request(protocol::IndexStats, args) end |
#logger(logger) ⇒ Object
43 44 45 |
# File 'lib/eson/client.rb', line 43 def logger(logger) protocol.logger end |
#logger=(logger) ⇒ Object
39 40 41 |
# File 'lib/eson/client.rb', line 39 def logger=(logger) protocol.logger = logger end |
#mget(args = {}) ⇒ Object
77 78 79 |
# File 'lib/eson/client.rb', line 77 def mget(args = {}) request(protocol::MultiGet, args) end |
#more_like_this(args = {}) ⇒ Object
118 119 120 |
# File 'lib/eson/client.rb', line 118 def more_like_this(args = {}) request(protocol::MoreLikeThis, args) end |
#msearch(args = {}, &block) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/eson/client.rb', line 106 def msearch(args = {}, &block) if block_given? request(protocol::MultiSearch, args, &block) else request(protocol::MultiSearch, args, false) end end |
#node ⇒ Object
35 36 37 |
# File 'lib/eson/client.rb', line 35 def node self.server end |
#nodes(args = {}) ⇒ Object
134 135 136 |
# File 'lib/eson/client.rb', line 134 def nodes(args = {}) request(protocol::Nodes, args) end |
#open_index(args = {}) ⇒ Object
158 159 160 |
# File 'lib/eson/client.rb', line 158 def open_index(args = {}) request(protocol::OpenIndex, args) end |
#optimize(args = {}) ⇒ Object
206 207 208 |
# File 'lib/eson/client.rb', line 206 def optimize(args = {}) request(protocol::Optimize, args) end |
#percolate(args = {}, &block) ⇒ Object
94 95 96 |
# File 'lib/eson/client.rb', line 94 def percolate(args = {}, &block) request(protocol::Percolate, args, &block) end |
#put_mapping(args = {}) ⇒ Object
178 179 180 |
# File 'lib/eson/client.rb', line 178 def put_mapping(args = {}) request(protocol::PutMapping, args) end |
#put_template(args = {}) ⇒ Object
182 183 184 |
# File 'lib/eson/client.rb', line 182 def put_template(args = {}) request(protocol::PutTemplate, args) end |
#refresh(args = {}) ⇒ Object
210 211 212 |
# File 'lib/eson/client.rb', line 210 def refresh(args = {}) request(protocol::Refresh, args) end |
#search(args = {}, immediate = auto_call, &block) ⇒ Object Also known as: query
81 82 83 |
# File 'lib/eson/client.rb', line 81 def search(args = {}, immediate = auto_call, &block) request(protocol::Search, args, immediate, &block) end |
#segments(args = {}) ⇒ Object
226 227 228 |
# File 'lib/eson/client.rb', line 226 def segments(args = {}) request(protocol::Segments, args) end |
#shutdown(args = {}) ⇒ Object
138 139 140 |
# File 'lib/eson/client.rb', line 138 def shutdown(args = {}) request(protocol::Shutdown, args) end |
#simple_search(args = {}) ⇒ Object
86 87 88 |
# File 'lib/eson/client.rb', line 86 def simple_search(args = {}) request(protocol::SimpleSearch, args) end |
#snapshot(args = {}) ⇒ Object
214 215 216 |
# File 'lib/eson/client.rb', line 214 def snapshot(args = {}) request(protocol::Snapshot, args) end |
#state(args = {}) ⇒ Object
126 127 128 |
# File 'lib/eson/client.rb', line 126 def state(args = {}) request(protocol::State, args) end |
#stats(args = {}) ⇒ Object
130 131 132 |
# File 'lib/eson/client.rb', line 130 def stats(args = {}) request(protocol::Stats, args) end |
#status(args = {}) ⇒ Object
218 219 220 |
# File 'lib/eson/client.rb', line 218 def status(args = {}) request(protocol::Status, args) end |
#update_settings(args = {}) ⇒ Object
198 199 200 |
# File 'lib/eson/client.rb', line 198 def update_settings(args = {}) request(protocol::UpdateSettings, args) end |