Class: Eson::Client

Inherits:
Object
  • Object
show all
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.

Examples:

Constructing an HTTP client

c = Eson::Client.new(:server => "http://127.0.0.1:9200", 
                     :protocol => Eson::HTTP, 
                     :plugins => [Eson::ResponseParser], 
                     :logger => 'test/test.log')

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

Requests collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Create a new client. The client object is protocol-independent, but uses Eson::HTTP by default.

Parameters:

  • opts (Hash) (defaults to: {})

    the options to create the client with.

Options Hash (opts):

  • :server (String) — default: 'http://127.0.0.1:9200'

    The base url of the server to connect to.

  • :protocol (Module) — default: Eson::HTTP

    The module providing the protocol implementation.

  • :plugins (Array<Module>) — default: []

    An array of plugin modules

  • :logger (String, #<<) — default: nil

    A logger object or a String pointing to a log file.

  • :auto_call (true, false) — default: true

    Whether to immeditately run the request or return the request object instead.

  • :auth (Hash) — default: nil

    Authentication information depending on protocol



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_callObject

Returns the value of attribute auto_call.



45
46
47
# File 'lib/eson/client.rb', line 45

def auto_call
  @auto_call
end

#default_parametersObject

Returns the value of attribute default_parameters.



41
42
43
# File 'lib/eson/client.rb', line 41

def default_parameters
  @default_parameters
end

#index_nameObject

Returns the value of attribute index_name.



40
41
42
# File 'lib/eson/client.rb', line 40

def index_name
  @index_name
end

#loggerObject

Returns the value of attribute logger.



46
47
48
# File 'lib/eson/client.rb', line 46

def logger
  @logger
end

#optsObject

Returns the value of attribute opts.



44
45
46
# File 'lib/eson/client.rb', line 44

def opts
  @opts
end

#pluginsObject

Returns the value of attribute plugins.



43
44
45
# File 'lib/eson/client.rb', line 43

def plugins
  @plugins
end

#protocolObject

Returns the value of attribute protocol.



42
43
44
# File 'lib/eson/client.rb', line 42

def protocol
  @protocol
end

#serverObject 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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Aliases.

Yields:

  • The block is evaluated in the context of the request to define the aliases



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Analyze.



447
448
449
# File 'lib/eson/client.rb', line 447

def analyze(args = {}, immediate = auto_call)
  request(protocol::Analyze, args, immediate)
end

#authHash

Returns the auth parameters

Returns:

  • (Hash)

    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.

Returns:

  • (true, false)

    Whether auth parameters are set.



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.

Parameters:

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Bulk.

Yields:

  • The block is evaluated to create the subrequests.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::ClearCache.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::CloseIndex.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Count.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::CreateIndex.



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

Deprecated.


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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Delete.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

Yields:

  • If eson-dsl is used, the given block will be used as DSL defintion.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::DeleteIndex.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::DeleteMapping.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::DeleteTemplate.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::IndexExists.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Explain.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Flush.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Get.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::GetAliases.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::GetMapping.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::GetSettings.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::GetTemplate.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Health.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Index.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::IndexStats.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::MGet.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

Yields:

  • If eson-dsl is used, the given block will be used as DSL defintion.



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.

Parameters:

Yields:

  • The block is evaluated to create the subrequests.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Nodes.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::OpenIndex.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Optimize.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Percolate.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::PutMapping.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::PutTemplate.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Refresh.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

Yields:

  • If eson-dsl is used, the given block will be used as DSL defintion.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Search.

Yields:

  • If eson-dsl is used, the given block will be used as DSL defintion.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Segments.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Shutdown.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::SimpleSearch.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Snapshot.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::State.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Stats.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Status.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Update.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::UpdateSettings.



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.

Overloads:

  • #Object

    With a block given, this will return a result.

    Returns:

    • (Object)

      result

  • #Eson::API

    Without immediate, this will method returns an request object.

    Returns:

Parameters:

  • immediate (true, false) (defaults to: auto_call)

    Whether to immediately call the request or not.

  • args (Hash) (defaults to: {})

    The arguments, as given in Shared::Validate.



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.

Parameters:

  • params (Hash) (defaults to: {})

    The new parameters

Returns:

  • (Eson::Client)

    a clone of the client with the new parameters set.



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