Class: Eson::Client
- Inherits:
-
Object
- Object
- Eson::Client
- Defined in:
- lib/eson/client.rb
Overview
Eson::Client is a protocol-agnostic client to elasticsearch. For an example of a protocol implementation, see HTTP. The client primarily constructs Request objects. In default mode, it also calls the backend immediately. This behaviour can be controlled using the parameter ‘auto_call`.
The client (like most parts of Eson) holds no state and can be reused. All operations that change parameters return a new Client object.
By default, the client returns the backend response as a raw backend response, unless a set of plugins is specified.
It is recommendable to use protocol-specific subclasses like HTTP::Client because they set sane defaults for the plugin-set and return better consumable data.
Constant Summary collapse
- DEFAULT_OPTS =
Default settings
{ :server => 'http://127.0.0.1:9200', :plugins => [], :logger => nil, :default_parameters => { :index => "default" } }
Instance Attribute Summary collapse
-
#auto_call ⇒ Object
Returns the value of attribute auto_call.
-
#default_parameters ⇒ Object
Returns the value of attribute default_parameters.
-
#index_name ⇒ Object
Returns the value of attribute index_name.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#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
(also: #node)
Returns the value of attribute server.
Requests collapse
-
#aliases(args = {}, immediate = auto_call) { ... } ⇒ Object
Creates a aliases request.
-
#analyze(args = {}, immediate = auto_call) ⇒ Object
Creates a analyze request.
-
#bulk(args = {}) { ... } ⇒ Object
Creates a bulk request.
-
#clear_cache(args = {}, immediate = auto_call) ⇒ Object
Creates a clear_cache request.
-
#close_index(args = {}, immediate = auto_call) ⇒ Object
Creates a close_index request.
-
#count(args = {}, immediate = auto_call) ⇒ Object
Creates a count request.
-
#create_index(args = {}, immediate = auto_call) ⇒ Object
Creates a create_index request.
-
#delete(args = {}, immediate = auto_call) ⇒ Object
Creates a delete request.
-
#delete_by_query(args = {}, immediate = auto_call) { ... } ⇒ Object
Creates a delete_by_query request.
-
#delete_index(args = {}, immediate = auto_call) ⇒ Object
Creates a delete_index request.
-
#delete_mapping(args = {}, immediate = auto_call) ⇒ Object
Creates a delete_mapping request.
-
#delete_template(args = {}, immediate = auto_call) ⇒ Object
Creates a delete_template request.
-
#exists?(args = {}, immediate = auto_call) ⇒ Object
Creates a exists? request.
-
#explain(args = {}, immediate = auto_call) ⇒ Object
Creates a explain request.
-
#flush(args = {}, immediate = auto_call) ⇒ Object
Creates a flush request.
-
#get(args = {}, immediate = auto_call) ⇒ Object
Creates a get request.
-
#get_aliases(args = {}, immediate = auto_call, &block) ⇒ Object
Creates a get_aliases request.
-
#get_mapping(args = {}, immediate = auto_call) ⇒ Object
Creates a get_mapping request.
-
#get_settings(args = {}, immediate = auto_call) ⇒ Object
Creates a get_settings request.
-
#get_template(args = {}, immediate = auto_call) ⇒ Object
Creates a get_template request.
-
#health(args = {}, immediate = auto_call) ⇒ Object
Creates a health request.
-
#index(args = {}, immediate = auto_call) ⇒ Object
Creates a index request.
-
#index_stats(args = {}, immediate = auto_call) ⇒ Object
Creates a index_stats request.
-
#mget(args = {}, immediate = auto_call) ⇒ Object
Creates a mget request.
-
#more_like_this(args = {}, immediate = auto_call) { ... } ⇒ Object
Creates a more_like_this request.
-
#msearch(args = {}) { ... } ⇒ Object
Creates a msearch request.
-
#nodes(args = {}, immediate = auto_call) ⇒ Object
Creates a nodes request.
-
#open_index(args = {}, immediate = auto_call) ⇒ Object
Creates a open_index request.
-
#optimize(args = {}, immediate = auto_call) ⇒ Object
Creates a optimize request.
-
#percolate(args = {}, immediate = auto_call, &block) ⇒ Object
Creates a percolate request.
-
#put_mapping(args = {}, immediate = auto_call) ⇒ Object
Creates a put_mapping request.
-
#put_template(args = {}, immediate = auto_call) ⇒ Object
Creates a put_template request.
-
#refresh(args = {}, immediate = auto_call) ⇒ Object
Creates a refresh request.
-
#scroll(args = {}, immediate = auto_call) { ... } ⇒ Object
Creates a scroll request.
-
#search(args = {}, immediate = auto_call) { ... } ⇒ Object
(also: #query)
Creates a search request.
-
#segments(args = {}, immediate = auto_call) ⇒ Object
Creates a segments request.
-
#shutdown(args = {}, immediate = auto_call) ⇒ Object
Creates a shutdown request.
-
#simple_search(args = {}, immediate = auto_call) ⇒ Object
Creates a simple_search request.
-
#snapshot(args = {}, immediate = auto_call) ⇒ Object
Creates a snapshot request.
-
#state(args = {}, immediate = auto_call) ⇒ Object
Creates a state request.
-
#stats(args = {}, immediate = auto_call) ⇒ Object
Creates a stats request.
-
#status(args = {}, immediate = auto_call) ⇒ Object
Creates a status request.
-
#update(args = {}, immediate = auto_call) ⇒ Object
Creates a update request.
-
#update_settings(args = {}, immediate = auto_call) ⇒ Object
Creates a update_settings request.
-
#validate(args = {}, immediate = auto_call) ⇒ Object
Creates a validate request.
Instance Method Summary collapse
-
#auth ⇒ Hash
Returns the auth parameters.
-
#auth? ⇒ true, false
Check whether the client has auth options set at all.
- #default_index=(index_name) ⇒ Object deprecated Deprecated.
-
#initialize(opts = {}) ⇒ Client
constructor
Create a new client.
-
#with(params = {}) ⇒ Eson::Client
Returns a clone of this client with new #default_parameters.
Constructor Details
#initialize(opts = {}) ⇒ Client
Create a new client. The client object is protocol-independent, but uses Eson::HTTP by default.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/eson/client.rb', line 69 def initialize(opts = {}) opts = DEFAULT_OPTS.merge(opts) self.opts = opts opts = opts.clone self.server = opts.delete(:server) default_index = opts.delete(:default_index) self.protocol = opts.delete(:protocol) || Eson::HTTP self.plugins = opts.delete(:plugins) self.logger = opts.delete(:logger) self.auto_call = opts.delete(:auto_call) self.default_parameters = opts.delete(:default_parameters) || {} if default_index default_parameters[:index] ||= default_index end if self.auto_call.nil? self.auto_call = true end end |
Instance Attribute Details
#auto_call ⇒ Object
Returns the value of attribute auto_call.
45 46 47 |
# File 'lib/eson/client.rb', line 45 def auto_call @auto_call end |
#default_parameters ⇒ Object
Returns the value of attribute default_parameters.
41 42 43 |
# File 'lib/eson/client.rb', line 41 def default_parameters @default_parameters end |
#index_name ⇒ Object
Returns the value of attribute index_name.
40 41 42 |
# File 'lib/eson/client.rb', line 40 def index_name @index_name end |
#logger ⇒ Object
Returns the value of attribute logger.
46 47 48 |
# File 'lib/eson/client.rb', line 46 def logger @logger end |
#opts ⇒ Object
Returns the value of attribute opts.
44 45 46 |
# File 'lib/eson/client.rb', line 44 def opts @opts end |
#plugins ⇒ Object
Returns the value of attribute plugins.
43 44 45 |
# File 'lib/eson/client.rb', line 43 def plugins @plugins end |
#protocol ⇒ Object
Returns the value of attribute protocol.
42 43 44 |
# File 'lib/eson/client.rb', line 42 def protocol @protocol end |
#server ⇒ Object Also known as: node
Returns the value of attribute server.
39 40 41 |
# File 'lib/eson/client.rb', line 39 def server @server end |
Instance Method Details
# ⇒ Object # ⇒ Eson::API
Creates a aliases request.
421 422 423 |
# File 'lib/eson/client.rb', line 421 def aliases(args = {}, immediate = auto_call, &block) request(protocol::Aliases, args, immediate, &block) end |
# ⇒ Object # ⇒ Eson::API
Creates a analyze request.
447 448 449 |
# File 'lib/eson/client.rb', line 447 def analyze(args = {}, immediate = auto_call) request(protocol::Analyze, args, immediate) end |
#auth ⇒ Hash
Returns the auth parameters
126 127 128 |
# File 'lib/eson/client.rb', line 126 def auth opts[:auth] end |
#auth? ⇒ true, false
Check whether the client has auth options set at all.
118 119 120 |
# File 'lib/eson/client.rb', line 118 def auth? !!opts[:auth] end |
#bulk(args = {}) { ... } ⇒ Object
Creates a bulk request.
If this method is called with a block, the request is immediately called. With no block given, the request will be returned.
286 287 288 289 290 291 292 |
# File 'lib/eson/client.rb', line 286 def bulk(args = {}, &block) if block_given? request(protocol::Bulk, args, &block) else request(protocol::Bulk, args, false) end end |
# ⇒ Object # ⇒ Eson::API
Creates a clear_cache request.
460 461 462 |
# File 'lib/eson/client.rb', line 460 def clear_cache(args = {}, immediate = auto_call) request(protocol::ClearCache, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a close_index request.
473 474 475 |
# File 'lib/eson/client.rb', line 473 def close_index(args = {}, immediate = auto_call) request(protocol::CloseIndex, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a count request.
245 246 247 |
# File 'lib/eson/client.rb', line 245 def count(args = {}, immediate = auto_call) request(protocol::Count, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a create_index request.
499 500 501 |
# File 'lib/eson/client.rb', line 499 def create_index(args = {}, immediate = auto_call) request(protocol::CreateIndex, args, immediate) end |
#default_index=(index_name) ⇒ Object
93 94 95 |
# File 'lib/eson/client.rb', line 93 def default_index=(index_name) default_index[:index] = index_name end |
# ⇒ Object # ⇒ Eson::API
Creates a delete request.
168 169 170 |
# File 'lib/eson/client.rb', line 168 def delete(args = {}, immediate = auto_call) request(protocol::Delete, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a delete_by_query request.
# @param [Hash] args The arguments, as given in Shared::DeleteByQuery.
324 325 326 |
# File 'lib/eson/client.rb', line 324 def delete_by_query(args = {}, immediate = auto_call, &block) request(protocol::DeleteByQuery, args, immediate, &block) end |
# ⇒ Object # ⇒ Eson::API
Creates a delete_index request.
512 513 514 |
# File 'lib/eson/client.rb', line 512 def delete_index(args = {}, immediate = auto_call) request(protocol::DeleteIndex, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a delete_mapping request.
525 526 527 |
# File 'lib/eson/client.rb', line 525 def delete_mapping(args = {}, immediate = auto_call) request(protocol::DeleteMapping, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a delete_template request.
590 591 592 |
# File 'lib/eson/client.rb', line 590 def delete_template(args = {}, immediate = auto_call) request(protocol::DeleteTemplate, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a exists? request.
720 721 722 723 724 |
# File 'lib/eson/client.rb', line 720 def exists?(args = {}, immediate = auto_call) request(protocol::IndexExists, args) rescue Eson::NotFoundError false end |
# ⇒ Object # ⇒ Eson::API
Creates a explain request.
735 736 737 |
# File 'lib/eson/client.rb', line 735 def explain(args = {}, immediate = auto_call) request(protocol::Explain, args) end |
# ⇒ Object # ⇒ Eson::API
Creates a flush request.
629 630 631 |
# File 'lib/eson/client.rb', line 629 def flush(args = {}, immediate = auto_call) request(protocol::Flush, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a get request.
180 181 182 |
# File 'lib/eson/client.rb', line 180 def get(args = {}, immediate = auto_call) request(protocol::Get, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a get_aliases request.
434 435 436 |
# File 'lib/eson/client.rb', line 434 def get_aliases(args = {}, immediate = auto_call, &block) request(protocol::GetAliases, args, immediate, &block) end |
# ⇒ Object # ⇒ Eson::API
Creates a get_mapping request.
538 539 540 |
# File 'lib/eson/client.rb', line 538 def get_mapping(args = {}, immediate = auto_call) request(protocol::GetMapping, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a get_settings request.
603 604 605 |
# File 'lib/eson/client.rb', line 603 def get_settings(args = {}, immediate = auto_call) request(protocol::GetSettings, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a get_template request.
577 578 579 |
# File 'lib/eson/client.rb', line 577 def get_template(args = {}, immediate = auto_call) request(protocol::GetTemplate, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a health request.
351 352 353 |
# File 'lib/eson/client.rb', line 351 def health(args = {}, immediate = auto_call) request(protocol::Health, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a index request.
156 157 158 |
# File 'lib/eson/client.rb', line 156 def index(args = {}, immediate = auto_call) request(protocol::Index, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a index_stats request.
694 695 696 |
# File 'lib/eson/client.rb', line 694 def index_stats(args = {}, immediate = auto_call) request(protocol::IndexStats, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a mget request.
192 193 194 |
# File 'lib/eson/client.rb', line 192 def mget(args = {}, immediate = auto_call) request(protocol::MultiGet, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a more_like_this request.
# @param [Hash] args The arguments, as given in Shared::MoreLikeThis.
338 339 340 |
# File 'lib/eson/client.rb', line 338 def more_like_this(args = {}, immediate = auto_call) request(protocol::MoreLikeThis, args, immediate) end |
#msearch(args = {}) { ... } ⇒ Object
Creates a msearch request.
If this method is called with a block, the request is immediately called. With no block given, the request will be returned.
306 307 308 309 310 311 312 |
# File 'lib/eson/client.rb', line 306 def msearch(args = {}, &block) if block_given? request(protocol::MultiSearch, args, &block) else request(protocol::MultiSearch, args, false) end end |
# ⇒ Object # ⇒ Eson::API
Creates a nodes request.
390 391 392 |
# File 'lib/eson/client.rb', line 390 def nodes(args = {}, immediate = auto_call) request(protocol::Nodes, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a open_index request.
486 487 488 |
# File 'lib/eson/client.rb', line 486 def open_index(args = {}, immediate = auto_call) request(protocol::OpenIndex, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a optimize request.
642 643 644 |
# File 'lib/eson/client.rb', line 642 def optimize(args = {}, immediate = auto_call) request(protocol::Optimize, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a percolate request.
270 271 272 |
# File 'lib/eson/client.rb', line 270 def percolate(args = {}, immediate = auto_call, &block) request(protocol::Percolate, args, immediate, &block) end |
# ⇒ Object # ⇒ Eson::API
Creates a put_mapping request.
551 552 553 |
# File 'lib/eson/client.rb', line 551 def put_mapping(args = {}, immediate = auto_call) request(protocol::PutMapping, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a put_template request.
564 565 566 |
# File 'lib/eson/client.rb', line 564 def put_template(args = {}, immediate = auto_call) request(protocol::PutTemplate, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a refresh request.
655 656 657 |
# File 'lib/eson/client.rb', line 655 def refresh(args = {}, immediate = auto_call) request(protocol::Refresh, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a scroll request.
220 221 222 |
# File 'lib/eson/client.rb', line 220 def scroll(args = {}, immediate = auto_call, &block) request(protocol::Scroll, args, immediate, &block) end |
# ⇒ Object # ⇒ Eson::API Also known as: query
Creates a search request.
206 207 208 |
# File 'lib/eson/client.rb', line 206 def search(args = {}, immediate = auto_call, &block) request(protocol::Search, args, immediate, &block) end |
# ⇒ Object # ⇒ Eson::API
Creates a segments request.
707 708 709 |
# File 'lib/eson/client.rb', line 707 def segments(args = {}, immediate = auto_call) request(protocol::Segments, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a shutdown request.
Please be aware that external node shutdown does not seem to be supported by ElasticSearch at the moment.
406 407 408 |
# File 'lib/eson/client.rb', line 406 def shutdown(args = {}, immediate = auto_call) request(protocol::Shutdown, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a simple_search request.
233 234 235 |
# File 'lib/eson/client.rb', line 233 def simple_search(args = {}, immediate = auto_call) request(protocol::SimpleSearch, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a snapshot request.
668 669 670 |
# File 'lib/eson/client.rb', line 668 def snapshot(args = {}, immediate = auto_call) request(protocol::Snapshot, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a state request.
364 365 366 |
# File 'lib/eson/client.rb', line 364 def state(args = {}, immediate = auto_call) request(protocol::State, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a stats request.
377 378 379 |
# File 'lib/eson/client.rb', line 377 def stats(args = {}, immediate = auto_call) request(protocol::Stats, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a status request.
681 682 683 |
# File 'lib/eson/client.rb', line 681 def status(args = {}, immediate = auto_call) request(protocol::Status, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a update request.
257 258 259 |
# File 'lib/eson/client.rb', line 257 def update(args = {}, immediate = auto_call) request(protocol::Update, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a update_settings request.
616 617 618 |
# File 'lib/eson/client.rb', line 616 def update_settings(args = {}, immediate = auto_call) request(protocol::UpdateSettings, args, immediate) end |
# ⇒ Object # ⇒ Eson::API
Creates a validate request.
748 749 750 |
# File 'lib/eson/client.rb', line 748 def validate(args = {}, immediate = auto_call) request(protocol::Validate, args) end |
#with(params = {}) ⇒ Eson::Client
Returns a clone of this client with new #default_parameters. The old parameters are merged with the new ones.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/eson/client.rb', line 103 def with(params = {}) client = self.clone client.default_parameters = default_parameters.merge(params) if block_given? yield client else client end end |