class ElasticRecord::Index
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
Attributes
disabled[RW]
load_from_source[RW]
model[RW]
partial_updates[RW]
Public Class Methods
new(model)
click to toggle source
# File lib/elastic_record/index.rb, line 43 def initialize(model) @model = model @disabled = false self.load_from_source = false end
Public Instance Methods
_insert_record(*args)
click to toggle source
# File lib/elastic_record/index.rb, line 74 def _insert_record(*args); end
_update_record(*args)
click to toggle source
# File lib/elastic_record/index.rb, line 75 def _update_record(*args); end
alias_name()
click to toggle source
# 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)
click to toggle source
# File lib/elastic_record/index.rb, line 53 def alias_name=(name) @alias_name = add_suffix(name) end
disable!()
click to toggle source
# File lib/elastic_record/index.rb, line 61 def disable! @disabled = true end
enable!()
click to toggle source
# File lib/elastic_record/index.rb, line 65 def enable! @disabled = false end
get(end_path, json = nil)
click to toggle source
# File lib/elastic_record/index.rb, line 90 def get(end_path, json = nil) path = "/#{alias_name}" path += "/#{mapping_type}" if custom_mapping_type_name? path += "/#{end_path}" connection.json_get path, json end
initialize_copy(other)
click to toggle source
# File lib/elastic_record/index.rb, line 49 def initialize_copy(other) @settings = settings.deep_dup end
load_from_source!()
click to toggle source
# 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() { || ... }
click to toggle source
# 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_connection()
click to toggle source
# File lib/elastic_record/index.rb, line 86 def real_connection model.elastic_connection end
Private Instance Methods
add_suffix(name)
click to toggle source
# File lib/elastic_record/index.rb, line 100 def add_suffix(name) suffix = ElasticRecord::Config.index_suffix if suffix && !name.end_with?(suffix) name + "_#{suffix}" else name end end
new_index_name()
click to toggle source
# File lib/elastic_record/index.rb, line 109 def new_index_name "#{alias_name}_#{Time.now.utc.strftime('%Y%m%d_%H%M%S')}" end