Class: ElasticsearchServerless::Client
- Inherits:
- 
      Object
      
        - Object
- ElasticsearchServerless::Client
 
- Includes:
- API
- Defined in:
- lib/elasticsearch-serverless.rb
Constant Summary collapse
- VALID_PARAMETERS =
- [:adapter, :log, :logger, :serializer_class, :trace, :tracer, :headers, :request_timeout, :retry_on_status, :retry_on_failure, :delay_on_retry, :opentelemetry_tracer_provider] 
- DEPRECATION_MESSAGE =
- 'WARNING: Starting with the release of the Elastic Stack 9.0.0, this client ' \ 'will be discontinued.' \ 'Instead, you can use the latest version of the Elasticsearch Client to build your ' \ 'Elasticsearch Serverless Ruby applications: ' \ "https://github.com/elastic/elasticsearch-ruby\n".freeze 
Constants included from API
API::API_NAMESPACES, API::HTTP_DELETE, API::HTTP_GET, API::HTTP_HEAD, API::HTTP_POST, API::HTTP_PUT, API::UPPERCASE_APIS
Instance Method Summary collapse
- #essential_parameters(url, api_key) ⇒ Object
- 
  
    
      #initialize(api_key:, url:, arguments: {})  ⇒ Client 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Initializes an Elasticsearch Serverless Client. 
- 
  
    
      #method_missing(name, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Metaprogramming for integration with Transport. 
- #respond_to_missing?(method_name, *args) ⇒ Boolean
- #user_agent ⇒ Object
- #validate_arguments(arguments) ⇒ Object
Methods included from API
Methods included from API::Actions
#bulk, #clear_scroll, #close_point_in_time, #count, #create, #delete, #delete_by_query, #delete_script, #exists, #exists_source, #explain, #field_caps, #get, #get_script, #get_source, #index, #info, #mget, #msearch, #msearch_template, #mtermvectors, #open_point_in_time, #ping, #put_script, #rank_eval, #reindex, #render_search_template, #scripts_painless_execute, #scroll, #search, #search_mvt, #search_template, #terms_enum, #termvector, #termvectors, #update, #update_by_query
Constructor Details
#initialize(api_key:, url:, arguments: {}) ⇒ Client
Initializes an Elasticsearch Serverless Client
| 57 58 59 60 61 62 | # File 'lib/elasticsearch-serverless.rb', line 57 def initialize(api_key:, url:, arguments: {}) validate_arguments(arguments) arguments.merge!(essential_parameters(url, api_key)) @transport = Elastic::Transport::Client.new(arguments) warn(DEPRECATION_MESSAGE) end | 
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Metaprogramming for integration with Transport
| 85 86 87 88 89 90 91 | # File 'lib/elasticsearch-serverless.rb', line 85 def method_missing(name, *args, &block) if methods.include?(name) super else @transport.send(name, *args, &block) end end | 
Instance Method Details
#essential_parameters(url, api_key) ⇒ Object
| 64 65 66 67 68 69 70 71 72 73 74 75 76 | # File 'lib/elasticsearch-serverless.rb', line 64 def essential_parameters(url, api_key) { host: url, transport_options: { headers: { 'Authorization' => "ApiKey #{api_key}", 'Elastic-Api-Version' => ElasticsearchServerless::API_VERSION, user_agent: user_agent } }, compression: true } end | 
#respond_to_missing?(method_name, *args) ⇒ Boolean
| 93 94 95 | # File 'lib/elasticsearch-serverless.rb', line 93 def respond_to_missing?(method_name, *args) @transport.respond_to?(method_name) || super end | 
#user_agent ⇒ Object
| 97 98 99 100 101 102 103 104 105 106 107 | # File 'lib/elasticsearch-serverless.rb', line 97 def user_agent user_agent = [ "elasticsearch-serverless-ruby/#{ElasticsearchServerless::VERSION}", "elastic-transport-ruby/#{Elastic::Transport::VERSION}", "RUBY_VERSION: #{RUBY_VERSION}" ] if RbConfig::CONFIG && RbConfig::CONFIG['host_os'] user_agent << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}" end user_agent.join('; ') end | 
#validate_arguments(arguments) ⇒ Object
| 78 79 80 81 82 | # File 'lib/elasticsearch-serverless.rb', line 78 def validate_arguments(arguments) arguments.map do |k, _| raise ArgumentError, "Parameter #{k}" unless VALID_PARAMETERS.include?(k) end end |