Class: Stretcher::Alias

Inherits:
EsComponent show all
Defined in:
lib/stretcher/alias.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from EsComponent

#do_alias, #do_delete_query, #do_refresh, #do_search, #request

Constructor Details

#initialize(index, name, options = {}) ⇒ Alias

Returns a new instance of Alias.



9
10
11
12
13
14
# 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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/stretcher/alias.rb', line 7

def name
  @name
end

Instance Method Details

#create(options = {}) ⇒ Object

Create the alias in elastic search with the given options

my_alias.create({ filter: { term: { user_id: 1 } } })


27
28
29
30
31
32
33
34
35
# File 'lib/stretcher/alias.rb', line 27

def create(options = {})
  request(:put) do |req|
    req.body = {
      actions: [
        add: options.merge(:alias => @name)
      ]
    }
  end
end

#deleteObject

Delete an alias from elastic search

my_alias.delete


40
41
42
# File 'lib/stretcher/alias.rb', line 40

def delete
  request(:delete)
end

#exist?Boolean

Determine whether an alias by this name exists

my_alias.exist? # true

Returns:

  • (Boolean)


47
48
49
50
51
52
# File 'lib/stretcher/alias.rb', line 47

def exist?
  request(:get)
  true
rescue Stretcher::RequestError::NotFound
  false
end

#index_contextObject

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: {} } })


20
21
22
# File 'lib/stretcher/alias.rb', line 20

def index_context
  @server.index(@name)
end