Class: Stretcher::Alias
- Inherits:
-
EsComponent
- Object
- EsComponent
- Stretcher::Alias
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#create(options = {}) ⇒ Object
Create the alias in elastic search with the given options.
-
#delete ⇒ Object
Delete an alias from elastic search.
-
#exist? ⇒ Boolean
Determine whether an alias by this name exists.
-
#index_context ⇒ Object
Get the index context of this alias (use it as if it was the index which it represents).
-
#initialize(index, name, options = {}) ⇒ Alias
constructor
A new instance of Alias.
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, = {}) @index = index @server = index.server @name = name @logger = [:logger] || server.logger end |
Instance Attribute Details
#name ⇒ Object (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( = {}) request(:put) do |req| req.body = { actions: [ add: .merge(:alias => @name) ] } end end |
#delete ⇒ Object
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
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_context ⇒ Object
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 |