Class: ElasticRecord::Index

Inherits:
Object
  • Object
show all
Includes:
Analyze, Deferred, Documents, Manage, Mapping, Settings
Defined in:
lib/elastic_record/index.rb,
lib/elastic_record/index/manage.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

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, Settings Classes: ScrollEnumerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Deferred

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

Methods included from Analyze

#analyze

Methods included from Mapping

#get_mapping, #mapping_body, #update_mapping

Methods included from Settings

#analysis_body, #settings, #settings=, #update_settings

Methods included from Manage

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

Methods included from Documents

#build_scroll_enumerator, #bulk, #bulk_add, #current_bulk_batch, #delete_by_query, #delete_document, #explain, #index_document, #index_record, #record_exists?, #scroll, #search, #update_document, #update_record

Constructor Details

#initialize(models) ⇒ Index

Returns a new instance of Index.



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

def initialize(models)
  models = Array.wrap(models)
  @model = models.first
  @doctypes = models.map(&:doctype)
  @disabled = false
end

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.



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

def disabled
  @disabled
end

#doctypesObject

Returns the value of attribute doctypes.



35
36
37
# File 'lib/elastic_record/index.rb', line 35

def doctypes
  @doctypes
end

#load_from_sourceObject

Returns the value of attribute load_from_source.



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

def load_from_source
  @load_from_source
end

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#partial_updatesObject

Returns the value of attribute partial_updates.



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

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 ||= 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 = 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, doctype = nil, json = nil) ⇒ Object



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

def get(end_path, doctype = nil, json = nil)
  path = "/#{alias_name}"
  path += "/#{doctype.name}" if doctype
  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

#loading_from_source(&block) ⇒ Object



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

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

#real_connectionObject



76
77
78
# File 'lib/elastic_record/index.rb', line 76

def real_connection
  model.elastic_connection
end