Class: Elasticsearch::Resources::Document

Inherits:
Object
  • Object
show all
Includes:
Describable, Identifiable, Queryable, Resource, Typeable
Defined in:
lib/elasticsearch/resources/document.rb

Instance Method Summary collapse

Methods included from Describable

included

Methods included from Identifiable

included

Methods included from Typeable

included

Methods included from Queryable

included

Methods included from Resource

included

Constructor Details

#initialize(type:, id:, attributes: {}) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
# File 'lib/elasticsearch/resources/document.rb', line 10

def initialize(type:, id:, attributes: {})
  self.type = type
  self.id = id
  self.attributes = attributes
end

Instance Method Details

#clientObject



24
25
26
# File 'lib/elasticsearch/resources/document.rb', line 24

def client
  type.client
end

#clusterObject



16
17
18
# File 'lib/elasticsearch/resources/document.rb', line 16

def cluster
  index.cluster
end

#create(options = {}) ⇒ Object



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

def create(options = {})
  params = {
    body: attributes
  }.merge(options)

  query(:create, params)
end

#find_clusterObject



60
61
62
# File 'lib/elasticsearch/resources/document.rb', line 60

def find_cluster
  self.cluster
end

#find_index(index: nil) ⇒ Object



64
65
66
# File 'lib/elasticsearch/resources/document.rb', line 64

def find_index(index: nil)
  self.index
end

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



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

def find_type(index: nil, type: nil)
  self.type
end

#indexObject



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

def index
  type.index
end

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



28
29
30
31
32
33
34
35
36
# File 'lib/elasticsearch/resources/document.rb', line 28

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

  super(action, **params)
end

#update(options = {}) ⇒ Object



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

def update(options = {})
  params = {
    body: attributes
  }.merge(options)

  query(:update, params)
end