class Stretcher::Alias

Represents an Alias in elastic search. Generally should be used via Index#alias(name)

Attributes

name[R]

Public Class Methods

new(index, name, options = {}) click to toggle source
# File lib/stretcher/alias.rb, line 9
def initialize(index, name, options = {})
  @index = index
  @server = index.server
  @name = name
  @logger = options[:logger] || server.logger
end

Public Instance Methods

create(options = {}) click to toggle source

Create the alias in elastic search with the given options

my_alias.create({ filter: { term: { user_id: 1 } } })
# File lib/stretcher/alias.rb, line 27
def create(options = {})
  request(:put) do |req|
    req.body = {
      actions: [
        add: options.merge(:alias => @name)
      ]
    }
  end
end
delete() click to toggle source

Delete an alias from elastic search

my_alias.delete
# File lib/stretcher/alias.rb, line 40
def delete
  request(:delete)
end
exist?() click to toggle source

Determine whether an alias by this name exists

my_alias.exist? # true
# File lib/stretcher/alias.rb, line 47
def exist?
  request(:get)
  true
rescue Stretcher::RequestError::NotFound
  false
end
index_context() click to toggle source

Get the index context of this alias (use it as if it was the index which it represents)

my_alias.index_context.search({ query: { match_all: {} } })
# File lib/stretcher/alias.rb, line 20
def index_context
  @server.index(@name)
end

Private Instance Methods

path_uri(path = nil) click to toggle source

Full path to this alias

# File lib/stretcher/alias.rb, line 57
def path_uri(path = nil)
  p = @index.path_uri("_alias/#{@name}")
  path ? p << "/#{path}" : p
end