Class: ElastomerClient::Client::MultiPercolate
- Inherits:
-
Object
- Object
- ElastomerClient::Client::MultiPercolate
- Defined in:
- lib/elastomer_client/client/multi_percolate.rb
Overview
The MultiPercolate class is a helper for accumulating and submitting multi_percolate API requests. Instances of the MultiPercolate class accumulate percolate actions and then issue a single API request to Elasticsearch, which runs all accumulated percolate actions in parallel and returns each result hash aggregated into an array of result hashes.
Instead of instantiating this class directly, use the block form of Client#multi_percolate.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#add_to_actions(action) ⇒ Object
Internal: Add an action to the pending request.
-
#call ⇒ Object
Execute the multi_percolate call with the accumulated percolate actions.
-
#count(doc, header = {}) ⇒ Object
Add a percolate acount action to the multi percolate request.
-
#initialize(client, params = {}) ⇒ MultiPercolate
constructor
Create a new MultiPercolate instance for accumulating percolate actions and submitting them all as a single request.
-
#percolate(doc, header = {}) ⇒ Object
Add a percolate action to the multi percolate request.
Constructor Details
#initialize(client, params = {}) ⇒ MultiPercolate
Create a new MultiPercolate instance for accumulating percolate actions and submitting them all as a single request.
client - ElastomerClient::Client used for HTTP requests to the server params - Parameters Hash to pass to the Client#multi_percolate method
68 69 70 71 72 73 |
# File 'lib/elastomer_client/client/multi_percolate.rb', line 68 def initialize(client, params = {}) @client = client @params = params @actions = [] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
75 76 77 |
# File 'lib/elastomer_client/client/multi_percolate.rb', line 75 def client @client end |
Instance Method Details
#add_to_actions(action) ⇒ Object
Internal: Add an action to the pending request. Actions can be either headers or bodies. The first action must be a percolate header, followed by a body, then alternating headers and bodies.
action - the Hash (header or body) to add to the pending request
Returns this MultiPercolate instance.
122 123 124 125 126 |
# File 'lib/elastomer_client/client/multi_percolate.rb', line 122 def add_to_actions(action) action = MultiJson.dump action @actions << action self end |
#call ⇒ Object
Execute the multi_percolate call with the accumulated percolate actions. If the accumulated actions list is empty then no action is taken.
Returns the response body Hash.
106 107 108 109 110 111 112 113 |
# File 'lib/elastomer_client/client/multi_percolate.rb', line 106 def call return if @actions.empty? body = @actions.join("\n") + "\n" client.multi_percolate(body, @params) ensure @actions.clear end |
#count(doc, header = {}) ⇒ Object
Add a percolate acount action to the multi percolate request. This percolate count action will not be executed until the multi_percolate API call is made.
header - A Hash of the index and type, if not provided in the params doc - A Hash of the document
Returns this MultiPercolate instance.
97 98 99 100 |
# File 'lib/elastomer_client/client/multi_percolate.rb', line 97 def count(doc, header = {}) add_to_actions(count: @params.merge(header)) add_to_actions(doc:) end |
#percolate(doc, header = {}) ⇒ Object
Add a percolate action to the multi percolate request. This percolate action will not be executed until the multi_percolate API call is made.
header - A Hash of the index and type, if not provided in the params doc - A Hash of the document
Returns this MultiPercolate instance.
84 85 86 87 |
# File 'lib/elastomer_client/client/multi_percolate.rb', line 84 def percolate(doc, header = {}) add_to_actions(percolate: @params.merge(header)) add_to_actions(doc:) end |