Class: Elastic::EnterpriseSearch::Client

Inherits:
Object
  • Object
show all
Includes:
Actions, Request, Utils
Defined in:
lib/elastic/enterprise-search/client.rb

Overview

API client for the Elastic Enterprise Search API. This is the main client from which the Workplace Search and App Search clients inherit.

Direct Known Subclasses

AppSearch::Client, WorkplaceSearch::Client

Constant Summary collapse

DEFAULT_TIMEOUT =
15

Constants included from Utils

Utils::DEFAULT_HOST

Instance Method Summary collapse

Methods included from Utils

#stringify_keys, symbolize_keys

Methods included from Actions

#health, #put_read_only, #read_only, #search_engines, #stats, #version

Methods included from Request

#basic_auth_header, #delete, #get, #post, #put, #request, #setup_authentication_header

Constructor Details

#initialize(options = {}) ⇒ Client

Create a new Elastic::EnterpriseSearch::Client client

Parameters:

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

    a hash of configuration options that will override what is set on the Elastic::EnterpriseSearch class.

  • arguments (Hash)

    a customizable set of options

  • enable_meta_header (Hash)

    a customizable set of options

Options Hash (options):

  • :host (String)

    Enterprise Search host

  • :basic_auth (Hash)

    a username and password for Basic Authentication

  • :overall_timeout (Numeric)

    overall timeout for requests in seconds (default: 15s)

  • :open_timeout (Numeric)

    the number of seconds Net::HTTP (default: 15s) will wait while opening a connection before raising a Timeout::Error

  • :proxy (String)

    url of proxy to use, ex: “localhost:8888

  • :log (Boolean)

    Use the default logger (disabled by default)



66
67
68
69
# File 'lib/elastic/enterprise-search/client.rb', line 66

def initialize(options = {})
  @options = options
  @transport = transport
end

Instance Method Details

#adapterObject



113
114
115
# File 'lib/elastic/enterprise-search/client.rb', line 113

def adapter
  @options[:adapter]
end

#app_search(options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/elastic/enterprise-search/client.rb', line 43

def app_search(options = {})
  @app_search ||= Elastic::EnterpriseSearch::AppSearch::Client.new(
    host: host,
    http_auth: options[:http_auth],
    transport: @transport
  )
end

#hostObject

Raises:

  • (URI::InvalidURIError)


125
126
127
128
129
130
131
# File 'lib/elastic/enterprise-search/client.rb', line 125

def host
  return DEFAULT_HOST unless @options[:host]

  raise URI::InvalidURIError unless @options[:host] =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/

  @options[:host]
end

#http_authObject



97
98
99
# File 'lib/elastic/enterprise-search/client.rb', line 97

def http_auth
  @options[:http_auth] || { user: 'elastic', password: 'changeme' }
end

#http_auth=(http_auth) ⇒ Object



101
102
103
# File 'lib/elastic/enterprise-search/client.rb', line 101

def http_auth=(http_auth)
  @options[:http_auth] = http_auth
end

#logObject



105
106
107
# File 'lib/elastic/enterprise-search/client.rb', line 105

def log
  @options[:log] || false
end

#loggerObject



109
110
111
# File 'lib/elastic/enterprise-search/client.rb', line 109

def logger
  @options[:logger]
end

#open_timeoutObject



89
90
91
# File 'lib/elastic/enterprise-search/client.rb', line 89

def open_timeout
  @options[:open_timeout] || DEFAULT_TIMEOUT
end

#overall_timeoutObject



93
94
95
# File 'lib/elastic/enterprise-search/client.rb', line 93

def overall_timeout
  (@options[:overall_timeout] || DEFAULT_TIMEOUT).to_f
end

#traceObject



121
122
123
# File 'lib/elastic/enterprise-search/client.rb', line 121

def trace
  @options[:trace]
end

#tracerObject



117
118
119
# File 'lib/elastic/enterprise-search/client.rb', line 117

def tracer
  @options[:tracer]
end

#transportObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/elastic/enterprise-search/client.rb', line 71

def transport
  @options[:transport] ||
    Elastic::Transport::Client.new(
      host: host,
      log: log,
      logger: logger,
      request_timeout: overall_timeout,
      adapter: adapter,
      transport_options: {
        request: { open_timeout: open_timeout },
        headers: { user_agent: user_agent }
      },
      enable_meta_header: @options[:enable_meta_header] || true,
      trace: trace,
      tracer: tracer
    )
end

#workplace_search(options = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/elastic/enterprise-search/client.rb', line 35

def workplace_search(options = {})
  @workplace_search ||= Elastic::EnterpriseSearch::WorkplaceSearch::Client.new(
    host: host,
    http_auth: options[:http_auth],
    transport: @transport
  )
end