Class: Elastic::Type

Inherits:
Elastic::Types::BaseType show all
Extended by:
Elastic::Types::FacetedType, Elastic::Types::NestableType, Forwardable
Includes:
Railties::TypeExtensions
Defined in:
lib/elastic/railtie.rb,
lib/elastic/type.rb

Overview

Add activerecord related index helpers

Instance Attribute Summary

Attributes inherited from Core::Serializer

#object

Class Method Summary collapse

Methods included from Elastic::Types::FacetedType

field, fields

Methods included from Elastic::Types::NestableType

nested

Methods included from Railties::TypeExtensions

included

Methods inherited from Elastic::Types::BaseType

definition, freeze_definition, #initialize, pre_definition, target=

Methods inherited from Core::Serializer

#as_elastic_document, #as_elastic_source, #fields, #initialize, original_value_occluded?

Constructor Details

This class inherits a constructor from Elastic::Types::BaseType

Class Method Details

.connectorObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/elastic/type.rb', line 33

def self.connector
  @connector ||= begin
    Elastic::Core::Connector.new(
      suffix,
      definition.as_es_mapping
    ).tap do |conn|
      if Elastic.config.whiny_indices && conn.status != :ready
        raise 'elastic index out of sync, try migrating'
      end
    end
  end
end

.default_suffixObject



13
14
15
# File 'lib/elastic/type.rb', line 13

def self.default_suffix
  to_s.underscore
end

.delete(_object) ⇒ Object



84
85
86
87
# File 'lib/elastic/type.rb', line 84

def self.delete(_object)
  connector.delete new(_object).as_elastic_document(only_meta: true)
  self
end

.dropObject



93
94
95
96
# File 'lib/elastic/type.rb', line 93

def self.drop
  connector.drop
  self
end

.import(_collection, batch_size: nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/elastic/type.rb', line 67

def self.import(_collection, batch_size: nil)
  batch_size = batch_size || import_batch_size

  Commands::ImportIndexDocuments.for(
    index: self,
    collection: _collection,
    batch_size: batch_size
  )

  self
end

.import_batch_sizeObject



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

def self.import_batch_size
  @import_batch_size || Elastic.config.import_batch_size
end

.import_batch_size=(_value) ⇒ Object



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

def self.import_batch_size=(_value)
  @import_batch_size = _value
end

.index(_object) ⇒ Object



79
80
81
82
# File 'lib/elastic/type.rb', line 79

def self.index(_object)
  connector.index new(_object).as_elastic_document
  self
end

.index_nameObject



46
47
48
# File 'lib/elastic/type.rb', line 46

def self.index_name
  connector.index_name
end

.migrateObject



50
51
52
53
# File 'lib/elastic/type.rb', line 50

def self.migrate
  connector.migrate(batch_size: import_batch_size)
  self
end

.queryObject



89
90
91
# File 'lib/elastic/type.rb', line 89

def self.query
  Query.new self
end

.refreshObject



98
99
100
101
# File 'lib/elastic/type.rb', line 98

def self.refresh
  connector.refresh
  self
end

.reindex(verbose: true) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/elastic/type.rb', line 55

def self.reindex(verbose: true)
  connector.rollover do
    Commands::ImportIndexDocuments.for(
      index: self,
      verbose: verbose,
      batch_size: import_batch_size
    )
  end

  self
end

.suffixObject



17
18
19
# File 'lib/elastic/type.rb', line 17

def self.suffix
  @suffix || default_suffix
end

.suffix=(_value) ⇒ Object



21
22
23
# File 'lib/elastic/type.rb', line 21

def self.suffix=(_value)
  @suffix = _value
end