@@ -181,22 +181,15 @@ def join_bulk_responses(bulk_responses)
181181
182182 def bulk_send(body_stream, batch_actions)
183183 params = compression_level? ? {:headers => {"Content-Encoding" => "gzip"}} : {}
184-
185184 response = @pool.post(@bulk_path, params, body_stream.string)
186-
187185 @bulk_response_metrics.increment(response.code.to_s)
188186
189- case response.code
190- when 200 # OK
187+ if response.code == 200
191188 LogStash::Json.load(response.body)
192- when 413 # Payload Too Large
193- logger.warn("Bulk request rejected: `413 Payload Too Large`", :action_count => batch_actions.size, :content_length => body_stream.size)
194- emulate_batch_error_response(batch_actions, response.code, 'payload_too_large')
195189 else
190+ logger.warn("Bulk request rejected: `413 Payload Too Large`", :action_count => batch_actions.size, :content_length => body_stream.size) if response.code == 413
196191 url = ::LogStash::Util::SafeURI.new(response.final_url)
197- raise ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new(
198- response.code, url, body_stream.to_s, response.body
199- )
192+ raise ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new(response.code, url, body_stream.to_s, response.body)
200193 end
201194 end
202195
@@ -414,13 +407,21 @@ def exists?(path, use_get=false)
414407 end
415408
416409 def template_exists?(template_endpoint, name)
417- exists?("/#{template_endpoint}/#{name}")
410+ response = @pool.get("/#{template_endpoint}/#{name}")
411+ return true if response.code >= 200 && response.code <= 299
412+ return false if response.code == 404
413+ url = ::LogStash::Util::SafeURI.new(response.final_url)
414+ raise BadResponseCodeError.new(response.code, url, nil, response.body)
418415 end
419416
420417 def template_put(template_endpoint, name, template)
421- path = "#{template_endpoint}/#{name}"
422418 logger.info("Installing Elasticsearch template", name: name)
423- @pool.put(path, nil, LogStash::Json.dump(template))
419+ path = "#{template_endpoint}/#{name}"
420+ response = @pool.put(path, nil, LogStash::Json.dump(template))
421+ if response.code < 200 || response.code > 299
422+ url = ::LogStash::Util::SafeURI.new(response.final_url)
423+ raise BadResponseCodeError.new(response.code, url, template, response.body)
424+ end
424425 end
425426
426427 # ILM methods
@@ -432,16 +433,14 @@ def rollover_alias_exists?(name)
432433
433434 # Create a new rollover alias
434435 def rollover_alias_put(alias_name, alias_definition)
435- begin
436- @pool.put(CGI::escape(alias_name), nil, LogStash::Json.dump(alias_definition))
437- logger.info("Created rollover alias", name: alias_name)
438- # If the rollover alias already exists, ignore the error that comes back from Elasticsearch
439- rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
440- if e.response_code == 400
441- logger.info("Rollover alias already exists, skipping", name: alias_name)
442- return
443- end
444- raise e
436+ response = @pool.put(CGI::escape(alias_name), nil, LogStash::Json.dump(alias_definition))
437+ if response.code == 400
438+ logger.info("Rollover alias already exists, skipping", name: alias_name)
439+ return
440+ end
441+ unless response.code >= 200 && response.code <= 299
442+ url = ::LogStash::Util::SafeURI.new(response.final_url)
443+ raise BadResponseCodeError.new(response.code, url, alias_definition, response.body)
445444 end
446445 end
447446
0 commit comments