Class: JayAPI::Elasticsearch::Client
- Inherits:
-
Object
- Object
- JayAPI::Elasticsearch::Client
- Extended by:
- Forwardable
- Includes:
- Mixins::RetriableRequests
- Defined in:
- lib/jay_api/elasticsearch/client.rb
Overview
The JayAPI wrapper class over the Elasticsearch::Client object. It mirrors the object’s API, but if one of the ERRORS is raised, this Wrapper class will rescue the error up to a few times and re-try the connection. This way the connection to Elasticsearch will be more robust.
Constant Summary
Constants included from Mixins::RetriableRequests
Mixins::RetriableRequests::NON_RETRIABLE_ERRORS, Mixins::RetriableRequests::RETRIABLE_ERRORS
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
-
#transport_client ⇒ Boolean
readonly
True if there is connectivity to the cluster, false otherwise.
-
#wait_strategy ⇒ Object
readonly
Returns the value of attribute wait_strategy.
Instance Method Summary collapse
-
#bulk(**args) ⇒ Object
Calls the Elasticsearch::Client’s #bulk method and retries the connection a few times if a ServerError occurs.
-
#delete_by_query(**args) ⇒ Object
Calls the
Elasticsearch::Client‘s #delete_by_query method forwarding the given parameters. -
#index(**args) ⇒ Object
Calls the Elasticsearch::Client’s #index method and retries the connection a few times if a ServerError occurs.
-
#initialize(transport_client, logger = nil, max_attempts:, wait_strategy:) ⇒ Client
constructor
A new instance of Client.
-
#search(**args) ⇒ Object
Calls the Elasticsearch::Client’s #search method and retries the connection a few times if a ServerError occurs.
-
#stats ⇒ JayAPI::Elasticsearch::Stats
An instance of the
Statsclass, which gives the caller access to Elasticsearch’s Statistics API. -
#task_by_id(**args) ⇒ Object
deprecated
Deprecated.
Use Tasks#by_id instead.
-
#tasks ⇒ JayAPI::Elasticsearch::Tasks
An instance of the
Tasksclass, which can be used to retrieve the status of the tasks running on the Elasticsearch cluster.
Methods included from Mixins::RetriableRequests
#non_retriable_errors, #retriable_errors
Constructor Details
#initialize(transport_client, logger = nil, max_attempts:, wait_strategy:) ⇒ Client
Returns a new instance of Client.
34 35 36 37 38 39 |
# File 'lib/jay_api/elasticsearch/client.rb', line 34 def initialize(transport_client, logger = nil, max_attempts:, wait_strategy:) @transport_client = transport_client @logger = logger || Logging.logger($stdout) @max_attempts = max_attempts @wait_strategy = wait_strategy end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
22 23 24 |
# File 'lib/jay_api/elasticsearch/client.rb', line 22 def logger @logger end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
22 23 24 |
# File 'lib/jay_api/elasticsearch/client.rb', line 22 def max_attempts @max_attempts end |
#transport_client ⇒ Boolean (readonly)
Returns True if there is connectivity to the cluster, false otherwise.
27 28 29 |
# File 'lib/jay_api/elasticsearch/client.rb', line 27 def transport_client @transport_client end |
#wait_strategy ⇒ Object (readonly)
Returns the value of attribute wait_strategy.
22 23 24 |
# File 'lib/jay_api/elasticsearch/client.rb', line 22 def wait_strategy @wait_strategy end |
Instance Method Details
#bulk(**args) ⇒ Object
Calls the Elasticsearch::Client’s #bulk method and retries the connection a few times if a ServerError occurs.
58 59 60 |
# File 'lib/jay_api/elasticsearch/client.rb', line 58 def bulk(**args) retry_request { transport_client.bulk(**args) } end |
#delete_by_query(**args) ⇒ Object
Calls the Elasticsearch::Client‘s #delete_by_query method forwarding the given parameters. If the request fails additional retries will be performed.
67 68 69 |
# File 'lib/jay_api/elasticsearch/client.rb', line 67 def delete_by_query(**args) retry_request { transport_client.delete_by_query(**args) } end |
#index(**args) ⇒ Object
Calls the Elasticsearch::Client’s #index method and retries the connection a few times if a ServerError occurs.
44 45 46 |
# File 'lib/jay_api/elasticsearch/client.rb', line 44 def index(**args) retry_request { transport_client.index(**args) } end |
#search(**args) ⇒ Object
Calls the Elasticsearch::Client’s #search method and retries the connection a few times if a ServerError occurs.
51 52 53 |
# File 'lib/jay_api/elasticsearch/client.rb', line 51 def search(**args) retry_request { transport_client.search(**args) } end |
#stats ⇒ JayAPI::Elasticsearch::Stats
Returns An instance of the Stats class, which gives the caller access to Elasticsearch’s Statistics API.
82 83 84 |
# File 'lib/jay_api/elasticsearch/client.rb', line 82 def stats @stats ||= ::JayAPI::Elasticsearch::Stats.new(transport_client) end |
#task_by_id(**args) ⇒ Object
Use Tasks#by_id instead.
Calls Elasticsearch::Client‘s #tasks.get method forwarding the given parameters. If the request fails, additional retries will be performed.
76 77 78 |
# File 'lib/jay_api/elasticsearch/client.rb', line 76 def task_by_id(**args) retry_request { transport_client.tasks.get(**args) } end |
#tasks ⇒ JayAPI::Elasticsearch::Tasks
Returns An instance of the Tasks class, which can be used to retrieve the status of the tasks running on the Elasticsearch cluster.
89 90 91 |
# File 'lib/jay_api/elasticsearch/client.rb', line 89 def tasks @tasks ||= ::JayAPI::Elasticsearch::Tasks.new(client: self) end |