Module: Elastictastic::BasicDocument::ClassMethods

Defined in:
lib/elastictastic/basic_document.rb

Instance Method Summary collapse

Instance Method Details

#any?TrueClass, FalseClass

Returns True if there are documents of this type in the default index.

Returns:

  • (TrueClass, FalseClass)

    True if there are documents of this type in the default index.



113
114
115
116
117
# File 'lib/elastictastic/basic_document.rb', line 113

delegate :find, :destroy_all, :sync_mapping, :inspect, :find_each,
:find_in_batches, :first, :count, :empty?, :any?, :all,
:query, :filter, :from, :size, :sort, :highlight, :fields,
:script_fields, :preference, :facets, :routing,
:to => :current_scope

#countFixnum

Returns The number of documents of this type in the default index.

Returns:

  • (Fixnum)

    The number of documents of this type in the default index.



# File 'lib/elastictastic/basic_document.rb', line 93

#destroy_allObject

Destroy all instances of this class in the default index



# File 'lib/elastictastic/basic_document.rb', line 47

#empty?TrueClass, FalseClass

Returns True if there are no documents of this type in the default index.

Returns:

  • (TrueClass, FalseClass)

    True if there are no documents of this type in the default index.



# File 'lib/elastictastic/basic_document.rb', line 99

#find_each(batch_options = {}) {|document, hit| ... } ⇒ Enumerator

Iterate over all documents in the default index, retrieving documents in batches using a cursor, but yielding them one by one.

Parameters:

  • batch_options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (batch_options):

  • :batch_size (Fixnum) — default: Elastictastic.config.default_batch_size

    How many documents to retrieve from the server in each batch.

  • :ttl (Fixnum) — default: 60

    How long to keep the cursor alive, in the case where search is performed with a cursor.

Yields:

  • (document, hit)

    Each result is yielded to the block

Yield Parameters:

  • document (Document)

    A materialized Document instance

  • hit (Hashie::Mash)

    The raw hit from ElasticSearch, wrapped in a Hashie::Mash. Useful for extracting metadata, e.g. highlighting

Returns:

  • (Enumerator)

    An enumerator, if no block is passed



# File 'lib/elastictastic/basic_document.rb', line 61

#find_in_batches(batch_options = {}) {|batch| ... } ⇒ Enumerator

Retrieve all documents in the default index, yielding them in batches.

Parameters:

  • batch_options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (batch_options):

  • :batch_size (Fixnum) — default: Elastictastic.config.default_batch_size

    How many documents to retrieve from the server in each batch.

  • :ttl (Fixnum) — default: 60

    How long to keep the cursor alive, in the case where search is performed with a cursor.

Yields:

  • (batch)

    Once for each batch of hits

Yield Parameters:

  • batch (Enumerator)

    An enumerator for this batch of hits. The enumerator will yield a materialized Document and a Hashie::Mash wrapping each raw hit.

Returns:

  • (Enumerator)

    An enumerator that yields batches, if no block is passed.



# File 'lib/elastictastic/basic_document.rb', line 74

#firstDocument

Returns The “first” document in the index (“first” is undefined).

Returns:

  • (Document)

    The “first” document in the index (“first” is undefined).



# File 'lib/elastictastic/basic_document.rb', line 86

#in_index(name_or_index) ⇒ Object



135
136
137
# File 'lib/elastictastic/basic_document.rb', line 135

def in_index(name_or_index)
  Scope.new(Elastictastic::Index(name_or_index), self)
end

#mappingObject



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/elastictastic/basic_document.rb', line 119

def mapping
  mapping_for_type = { 'properties' => properties }
  mapping_for_type['_boost'] = @_boost if @_boost
  if @_routing_field
    mapping_for_type['_routing'] = {
      'path' => @_routing_field.to_s,
      'required' => @_routing_required
    }
  end
  { type => mapping_for_type }
end

#scoped(params) ⇒ Object



139
140
141
# File 'lib/elastictastic/basic_document.rb', line 139

def scoped(params)
  current_scope.scoped(params)
end

#sync_mappingObject

Push the mapping defined in this class to ElasticSearch. Be sure to do this before saving instances of your class, or after making changes to the class’s mapping (e.g. adding fields)



# File 'lib/elastictastic/basic_document.rb', line 53

#typeObject



131
132
133
# File 'lib/elastictastic/basic_document.rb', line 131

def type
  name.underscore
end