module Elastictastic::BasicDocument

The top-level module mixed in to classes which will be mapped as ElasticSearch documents. Note that most people will want to use the Document mixin, which extends BasicDocument with ActiveModel functionality such as validations, lifecycle hooks, observers, mass-assignment security, etc. The BasicDocument module is exposed directly for those who wish to avoid the performance penalty associated with ActiveModel functionality, or those who wish to only mix in the ActiveModel modules they need.

Most of the functionality for BasicDocument is provided by submodules; see below.

@see Document @see Scoped @see Properties @see Persistence @see OptimisticLocking @see ParentChild

Attributes

id[R]
version[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/elastictastic/basic_document.rb, line 159
def initialize(attributes = {})
  self.class.current_scope.initialize_instance(self)
end

Public Instance Methods

==(other) click to toggle source
# File lib/elastictastic/basic_document.rb, line 200
def ==(other)
  index == other.index && self.class == other.class && id == other.id
end
attributes() click to toggle source
# File lib/elastictastic/basic_document.rb, line 204
def attributes
  { :id => id, :index => index.name }
end
id=(id) click to toggle source
# File lib/elastictastic/basic_document.rb, line 190
def id=(id)
  assert_transient!
  @id = id
end
index() click to toggle source
# File lib/elastictastic/basic_document.rb, line 195
def index
  return @index if defined? @index
  @index = Index.default
end
inspect() click to toggle source
# File lib/elastictastic/basic_document.rb, line 208
def inspect
  inspected = "#<#{self.class.name} id: #{id}, index: #{index.name}"
  attributes.each_pair do |attr, value|
    inspected << ", #{attr}: #{value.inspect}"
  end
  embeds.each_pair do |attr, value|
    inspected << ", #{attr}: #{value.inspect}"
  end
  inspected << ">"
end
reload() click to toggle source
# File lib/elastictastic/basic_document.rb, line 163
def reload
  params = {}
  params['routing'] = @_parent_id if @_parent_id
  self.elasticsearch_hit =
    Elastictastic.client.get(index, self.class.type, id, params)
end