Class: Elasticsearch::Resources::Cluster

Inherits:
Object
  • Object
show all
Includes:
Configurable, Queryable, Resource
Defined in:
lib/elasticsearch/resources/cluster.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

included

Methods included from Queryable

included

Methods included from Resource

included

Constructor Details

#initialize(&block) ⇒ Cluster

Returns a new instance of Cluster.



10
11
12
# File 'lib/elasticsearch/resources/cluster.rb', line 10

def initialize(&block)
  configure(&block)
end

Class Method Details

.indexesObject



71
72
73
74
75
# File 'lib/elasticsearch/resources/cluster.rb', line 71

def self.indexes
  (@index_names ||= {}).collect do |key, index_name|
    [key, Object.const_get(index_name)]
  end.to_h
end

Instance Method Details

#build_index(key:, index_class: nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/elasticsearch/resources/cluster.rb', line 32

def build_index(key:, index_class: nil)
  index_class = self.class.indexes[key] if index_class.nil?
  index_class&.new(cluster: self).tap do |index|
    settings.index(key).tap do |settings|
      index.settings = settings.dup unless settings.nil?
    end
  end
end

#clientObject



19
20
21
# File 'lib/elasticsearch/resources/cluster.rb', line 19

def client
  settings.client
end

#count(body, options = {}) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/elasticsearch/resources/cluster.rb', line 49

def count(body, options = {})
  params = {
    body: body
  }.merge(options)

  query(:count, params)
end

#find_clusterObject



57
58
59
# File 'lib/elasticsearch/resources/cluster.rb', line 57

def find_cluster
  self
end

#find_index(index:) ⇒ Object



61
62
63
64
65
# File 'lib/elasticsearch/resources/cluster.rb', line 61

def find_index(index:)
  indexes.values.find do |i|
    i.find_index(index: index)
  end
end

#find_type(index:, type:) ⇒ Object



67
68
69
# File 'lib/elasticsearch/resources/cluster.rb', line 67

def find_type(index:, type:)
  find_index(index: index)&.find_type(index: index, type: type)
end

#indexesObject



23
24
25
26
27
28
29
30
# File 'lib/elasticsearch/resources/cluster.rb', line 23

def indexes
  @indexes ||= self.class.indexes.collect do |key, index_class|
    [
      key,
      build_index(key: key)
    ]
  end.to_h
end

#search(body, options = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/elasticsearch/resources/cluster.rb', line 41

def search(body, options = {})
  params = {
    body: body
  }.merge(options)

  query(:search, params)
end

#setup!Object



14
15
16
17
# File 'lib/elasticsearch/resources/cluster.rb', line 14

def setup!
  client
  super
end