Class: Elasticsearch::Extensions::Documents::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch/extensions/documents/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter = nil) ⇒ Index

Returns a new instance of Index.



9
10
11
# File 'lib/elasticsearch/extensions/documents/index.rb', line 9

def initialize(adapter = nil)
  @adapter = adapter || Documents.index_adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/elasticsearch/extensions/documents/index.rb', line 7

def adapter
  @adapter
end

Instance Method Details

#bulk_index(documents) ⇒ Object



45
46
47
# File 'lib/elasticsearch/extensions/documents/index.rb', line 45

def bulk_index(documents)
  adapter.bulk_index(documents)
end

#delete(document) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/elasticsearch/extensions/documents/index.rb', line 22

def delete(document)
  payload = {
    type:   document.class.type,
    id:     document.id,
  }
  adapter.delete payload
rescue Elasticsearch::Transport::Transport::Errors::NotFound => not_found
  Documents.logger.info "[Documents] Attempted to delete missing document: #{not_found}"
end

#index(document) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/elasticsearch/extensions/documents/index.rb', line 13

def index(document)
  payload = {
    type:   document.class.type,
    id:     document.id,
    body:   document.as_hash,
  }
  adapter.index payload
end

#refreshObject



37
38
39
# File 'lib/elasticsearch/extensions/documents/index.rb', line 37

def refresh
  adapter.refresh
end

#reindex(options = {}, &block) ⇒ Object



41
42
43
# File 'lib/elasticsearch/extensions/documents/index.rb', line 41

def reindex(options = {}, &block)
  adapter.reindex(options, &block)
end

#search(query) ⇒ Object



32
33
34
35
# File 'lib/elasticsearch/extensions/documents/index.rb', line 32

def search(query)
  response = adapter.search(query.as_hash)
  Hashie::Mash.new(response)
end