lib/esse/backend/index/update.rb in esse-0.2.0 vs lib/esse/backend/index/update.rb in esse-0.2.2
- old
+ new
@@ -19,11 +19,11 @@
# unavailable (missing, closed, etc)
# @option options [Boolean] :update_all_types Whether to update the mapping for all fields
# with the same name across all types
# @option options [Time] :timeout Explicit operation timeout
# @option options [Boolean] :master_timeout Timeout for connection to master
- # @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
+ # @raise [Esse::Backend::ServerError]
# in case of failure
# @return [Hash] the elasticsearch response
#
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
def update_mapping!(suffix: index_version, **options)
@@ -31,11 +31,11 @@
body = mappings_hash.fetch(Esse::MAPPING_ROOT_KEY)
if (type = options[:type])
body = body[type.to_s] || body[type.to_sym]
end
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: body)
- payload[:response] = client.indices.put_mapping(**opts)
+ payload[:response] = coerce_exception { client.indices.put_mapping(**opts) }
end
end
# Create or update a mapping
#
@@ -57,11 +57,11 @@
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
#
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
def update_mapping(suffix: index_version, **options)
update_mapping!(suffix: suffix, **options)
- rescue Elasticsearch::Transport::Transport::ServerError
+ rescue ServerError
{ 'errors' => true }
end
# Closes the index for read/write operations, updates the index settings, and open it again
#
@@ -74,11 +74,11 @@
# @option options [Boolean] :include_defaults Whether to return all default clusters setting
# @option options [Boolean] :preserve_existing Whether to update existing settings.
# If set to `true` existing settings on an index remain unchanged, the default is `false`
# @option options [Time] :master_timeout Specify timeout for connection to master
# @option options [Boolean] :flat_settings Return settings in flat format (default: false)
- # @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
+ # @raise [Esse::Backend::ServerError]
# in case of failure
# @return [Hash] the elasticsearch response
#
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
def update_settings!(suffix: index_version, **options)
@@ -91,22 +91,22 @@
if settings.any?
# When changing the number of replicas the index needs to be open. Changing the number of replicas on a
# closed index might prevent the index to be opened correctly again.
Esse::Events.instrument('elasticsearch.update_settings') do |payload|
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: { index: settings })
- payload[:response] = response = client.indices.put_settings(**opts)
+ payload[:response] = response = coerce_exception { client.indices.put_settings(**opts) }
end
end
if analysis
# It is also possible to define new analyzers for the index. But it is required to close the
# index first and open it after the changes are made.
close!(suffix: suffix)
begin
Esse::Events.instrument('elasticsearch.update_settings') do |payload|
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: { analysis: analysis })
- payload[:response] = response = client.indices.put_settings(**opts)
+ payload[:response] = response = coerce_exception { client.indices.put_settings(**opts) }
end
ensure
open!(suffix: suffix)
end
end
@@ -130,10 +130,10 @@
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
#
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
def update_settings(suffix: index_version, **options)
update_settings!(suffix: suffix, **options)
- rescue Elasticsearch::Transport::Transport::ServerError
+ rescue ServerError
{ 'errors' => true }
end
end
include InstanceMethods