Class: Elasticsearch::Client
- Inherits:
-
Object
- Object
- Elasticsearch::Client
- Includes:
- API
- Defined in:
- lib/elasticsearch.rb
Overview
This is the stateful Elasticsearch::Client, using an instance of elastic-transport.
Constant Summary collapse
- DEFAULT_CLOUD_PORT =
The default port to use if connecting using a Cloud ID. Updated from 9243 to 443 in client version 7.10.1
443
Instance Method Summary collapse
-
#initialize(arguments = {}, &block) ⇒ Client
constructor
Create a client connected to an Elasticsearch cluster.
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, *args) ⇒ Boolean
Constructor Details
#initialize(arguments = {}, &block) ⇒ Client
Create a client connected to an Elasticsearch cluster.
47 48 49 50 51 52 53 54 55 |
# File 'lib/elasticsearch.rb', line 47 def initialize(arguments = {}, &block) @verified = false @warned = false @opaque_id_prefix = arguments[:opaque_id_prefix] || nil api_key(arguments) if arguments[:api_key] setup_cloud(arguments) if arguments[:cloud_id] set_user_agent!(arguments) unless sent_user_agent?(arguments) @transport = Elastic::Transport::Client.new(arguments, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/elasticsearch.rb', line 57 def method_missing(name, *args, &block) if methods.include?(name) super elsif name == :perform_request # The signature for perform_request is: # method, path, params, body, headers, opts if (opaque_id = args[2]&.delete(:opaque_id)) headers = args[4] || {} opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id args[4] = headers.merge('X-Opaque-Id' => opaque_id) end unless @verified verify_elasticsearch(*args, &block) else @transport.perform_request(*args, &block) end else @transport.send(name, *args, &block) end end |
Instance Method Details
#respond_to_missing?(method_name, *args) ⇒ Boolean
78 79 80 |
# File 'lib/elasticsearch.rb', line 78 def respond_to_missing?(method_name, *args) @transport.respond_to?(method_name) || super end |