Class: Elasticsearch::Resources::Type

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

Constant Summary collapse

ACTIONS =
[
  :exists?,
  :create,
  :update,
  :delete,
  :get
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Nameable

included

Methods included from Indexable

included

Methods included from Configurable

included

Methods included from Queryable

included

Methods included from Resource

included

Constructor Details

#initialize(index:, &block) ⇒ Type

Returns a new instance of Type.



20
21
22
23
# File 'lib/elasticsearch/resources/type.rb', line 20

def initialize(index:, &block)
  self.index = index
  configure(&block)
end

Class Method Details

.document_classObject



84
85
86
# File 'lib/elasticsearch/resources/type.rb', line 84

def self.document_class
  Object.const_get(@document_class) if @document_class
end

Instance Method Details

#clientObject



29
30
31
# File 'lib/elasticsearch/resources/type.rb', line 29

def client
  index.client
end

#clusterObject



25
26
27
# File 'lib/elasticsearch/resources/type.rb', line 25

def cluster
  index.cluster
end

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



54
55
56
57
58
59
60
# File 'lib/elasticsearch/resources/type.rb', line 54

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

  query(:count, params)
end

#document_classObject



80
81
82
# File 'lib/elasticsearch/resources/type.rb', line 80

def document_class
  self.class.document_class
end

#find_clusterObject



68
69
70
# File 'lib/elasticsearch/resources/type.rb', line 68

def find_cluster
  self.cluster
end

#find_index(index: nil) ⇒ Object



72
73
74
# File 'lib/elasticsearch/resources/type.rb', line 72

def find_index(index: nil)
  self.index
end

#find_type(index: nil, type:) ⇒ Object



76
77
78
# File 'lib/elasticsearch/resources/type.rb', line 76

def find_type(index: nil, type:)
  matches_name?(type) ? self : nil
end

#nameObject



33
34
35
# File 'lib/elasticsearch/resources/type.rb', line 33

def name
  settings.name
end

#query(action, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/elasticsearch/resources/type.rb', line 37

def query(action, options = {})
  params = {
    index: index.name,
    type: name
  }.merge(options)

  super(action, **params)
end

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



46
47
48
49
50
51
52
# File 'lib/elasticsearch/resources/type.rb', line 46

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

  query(:search, params)
end