Class: ElasticRecord::Index

Inherits:
Object
  • Object
show all
Includes:
Analyze, Deferred, Documents, Manage, Mapping, MappingType, Search, Settings
Defined in:
lib/elastic_record/index.rb,
lib/elastic_record/index/manage.rb,
lib/elastic_record/index/search.rb,
lib/elastic_record/index/analyze.rb,
lib/elastic_record/index/mapping.rb,
lib/elastic_record/index/deferred.rb,
lib/elastic_record/index/settings.rb,
lib/elastic_record/index/documents.rb,
lib/elastic_record/index/mapping_type.rb

Overview

ElasticRecord::Index provides access to elastic search’s API. It is accessed with Widget.elastic_index. The methods provided are:

create

Create a new index that is not aliased

create_and_deploy

Create a new index and alias it

reset

Delete all aliased indexes and deploy a new one

refresh

Call the refresh API

exists?(index_name)

Returns if the index exists

get_mapping

Returns the mapping currently stored by elastic search.

update_mapping

Update elastic search’s mapping

Defined Under Namespace

Modules: Analyze, Deferred, Documents, Manage, Mapping, MappingType, Search, Settings Classes: ScrollEnumerator

Constant Summary

Constants included from MappingType

MappingType::DEFAULT_MAPPING_TYPE

Constants included from Mapping

Mapping::DEFAULT_MAPPING

Instance Attribute Summary collapse

Attributes included from MappingType

#mapping_type

Attributes included from Mapping

#mapping

Instance Method Summary collapse

Methods included from MappingType

#custom_mapping_type_name?

Methods included from Deferred

#connection, #deferred_connection, #disable_deferring!, #enable_deferring!, #reset_deferring!

Methods included from Analyze

#analyze

Methods included from Mapping

#get_mapping, #update_mapping

Methods included from Settings

#settings, #settings=, #update_settings

Methods included from Manage

#aliased_names, #all_names, #create, #create_and_deploy, #delete, #delete_all, #deploy, #exists?, #refresh, #reset

Methods included from Documents

#bulk, #bulk_add, #current_bulk_batch, #delete_by_query, #delete_document, #index_document, #index_record, #update_document, #update_record

Methods included from Search

#build_scroll_enumerator, #delete_scroll, #explain, #multi_search, #record_exists?, #scroll, #search

Constructor Details

#initialize(model) ⇒ Index

Returns a new instance of Index.


43
44
45
46
47
# File 'lib/elastic_record/index.rb', line 43

def initialize(model)
  @model = model
  @disabled = false
  self.load_from_source = false
end

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.


38
39
40
# File 'lib/elastic_record/index.rb', line 38

def disabled
  @disabled
end

#load_from_sourceObject

Returns the value of attribute load_from_source.


41
42
43
# File 'lib/elastic_record/index.rb', line 41

def load_from_source
  @load_from_source
end

#modelObject

Returns the value of attribute model.


39
40
41
# File 'lib/elastic_record/index.rb', line 39

def model
  @model
end

#partial_updatesObject

Returns the value of attribute partial_updates.


40
41
42
# File 'lib/elastic_record/index.rb', line 40

def partial_updates
  @partial_updates
end

Instance Method Details

#alias_nameObject


57
58
59
# File 'lib/elastic_record/index.rb', line 57

def alias_name
  @alias_name ||= add_suffix(model.base_class.name.demodulize.underscore.pluralize)
end

#alias_name=(name) ⇒ Object


53
54
55
# File 'lib/elastic_record/index.rb', line 53

def alias_name=(name)
  @alias_name = add_suffix(name)
end

#disable!Object


61
62
63
# File 'lib/elastic_record/index.rb', line 61

def disable!
  @disabled = true
end

#enable!Object


65
66
67
# File 'lib/elastic_record/index.rb', line 65

def enable!
  @disabled = false
end

#get(end_path, json = nil) ⇒ Object


90
91
92
93
94
95
96
# File 'lib/elastic_record/index.rb', line 90

def get(end_path, json = nil)
  path = "/#{alias_name}"
  path += "/#{mapping_type}"
  path += "/#{end_path}"

  connection.json_get path, json
end

#initialize_copy(other) ⇒ Object


49
50
51
# File 'lib/elastic_record/index.rb', line 49

def initialize_copy(other)
  @settings = settings.deep_dup
end

#load_from_source!Object


69
70
71
72
73
74
75
76
77
# File 'lib/elastic_record/index.rb', line 69

def load_from_source!
  self.load_from_source = true
  model.singleton_class.delegate :find, :find_by, :find_each, :find_in_batches, :first, to: :elastic_search

  model.instance_eval do
    def _insert_record(*args); end
    def _update_record(*args); end
  end
end

#loading_from_source(&block) ⇒ Object


79
80
81
82
83
84
# File 'lib/elastic_record/index.rb', line 79

def loading_from_source(&block)
  self.load_from_source = true
  yield
ensure
  self.load_from_source = false
end

#real_connectionObject


86
87
88
# File 'lib/elastic_record/index.rb', line 86

def real_connection
  model.elastic_connection
end