lib/esse/backend/index/aliases.rb in esse-0.2.0 vs lib/esse/backend/index/aliases.rb in esse-0.2.2
- old
+ new
@@ -9,34 +9,34 @@
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
# @param options [Array] :index list of serialized documents to be indexed(Optional)
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.5/indices-aliases.html
def aliases(**options)
- response = client.indices.get_alias({ index: index_name, name: '*' }.merge(options))
+ response = coerce_exception { client.indices.get_alias({ index: index_name, name: '*' }.merge(options)) }
idx_name = response.keys.find { |idx| idx.start_with?(index_name) }
return [] unless idx_name
response.dig(idx_name, 'aliases')&.keys || []
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
+ rescue NotFoundError
[]
end
# Returns a list of indices.
#
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
# @return [Array] list of indices that match with `index_name`.
def indices(**options)
- client.indices.get_alias({ name: index_name }.merge(options)).keys
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
+ coerce_exception { client.indices.get_alias({ name: index_name }.merge(options)).keys }
+ rescue NotFoundError
[]
end
# Replaces all existing aliases by the respective suffixed index from argument.
#
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
# @option [String] :suffix The suffix of the index used for versioning.
- # @raise [Elasticsearch::Transport::Transport::Errors::NotFound] in case of failure
+ # @raise [Esse::Backend::NotFoundError] in case of failure
# @return [Hash] the elasticsearch response
def update_aliases!(suffix:, **options)
raise(ArgumentError, 'index suffix cannot be nil') if suffix.nil?
options[:body] = {
@@ -48,22 +48,22 @@
],
}
Esse::Events.instrument('elasticsearch.update_aliases') do |payload|
payload[:request] = options
- payload[:response] = client.indices.update_aliases(options)
+ payload[:response] = coerce_exception { client.indices.update_aliases(options)}
end
end
# Replaces all existing aliases by the respective suffixed index from argument.
#
# @param options [Hash] Hash of paramenters that will be passed along to elasticsearch request
# @option [String] :suffix The suffix of the index used for versioning.
- # @raise [Elasticsearch::Transport::Transport::Errors::NotFound] in case of failure
+ # @raise [Esse::Backend::NotFoundError] in case of failure
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
def update_aliases(suffix:, **options)
update_aliases!(suffix: suffix, **options)
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
+ rescue NotFoundError
{ 'errors' => true }
end
end
include InstanceMethods