Class: ElasticsearchRecord::ModelApi
- Inherits:
-
Object
- Object
- ElasticsearchRecord::ModelApi
- Defined in:
- lib/elasticsearch_record/model_api.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#alias_exists? ⇒ Boolean
Shortcut for alias_exists.
-
#aliases ⇒ Hash
Shortcut for aliases.
-
#backup!(to: nil, close: true) ⇒ String
Shortcut for backup_table.
-
#block! ⇒ Boolean
Shortcut to block write access on the index.
-
#bulk(data, operation = :index, refresh: true, **options) ⇒ Object
bulk handle provided data (single Hash or multiple Array
). -
#clone!(target_name, **options) ⇒ Boolean
Shortcut for clone_table.
-
#close! ⇒ Boolean
Shortcut to close the opened index.
-
#create!(force: false, copy_from: nil, if_not_exists: false, **options) ⇒ Boolean
Shortcut for create_table.
-
#delete(data, **options) ⇒ Object
fast delete data.
-
#drop!(confirm: false) ⇒ Boolean
Shortcut to drop the index.
-
#exists? ⇒ Boolean
Shortcut for exists.
-
#index(data, **options) ⇒ Object
fast insert/update data.
-
#initialize(klass) ⇒ ModelApi
constructor
A new instance of ModelApi.
-
#insert(data, **options) ⇒ Object
fast insert new data.
-
#mapping_exists? ⇒ Boolean
Shortcut for mapping_exists.
-
#mappings ⇒ Hash
Shortcut for mappings.
-
#meta_exists? ⇒ Boolean
Shortcut for meta_exists.
-
#metas ⇒ Hash
Shortcut for metas.
-
#open! ⇒ Boolean
Shortcut to open the closed index.
-
#refresh! ⇒ Boolean
Shortcut to refresh the index.
-
#reindex!(target_name, **options) ⇒ Hash
Shortcut for reindex_table.
-
#rename!(target_name, timeout: nil, **options) ⇒ Object
Shortcut for rename_table.
-
#restore!(from: , timeout: nil, open: true, drop_backup: false) ⇒ Boolean
Shortcut for restore_table.
-
#schema(features = []) ⇒ Hash
Shortcut for schema.
-
#setting_exists? ⇒ Boolean
Shortcut for setting_exists.
-
#settings(flat_settings = true) ⇒ Hash
Shortcut for settings.
-
#state ⇒ Hash
Shortcut for state.
-
#truncate!(confirm: false) ⇒ Boolean
Shortcut to truncate the index.
-
#unblock! ⇒ Boolean
Shortcut to unblock all blocked accesses on the index.
-
#update(data, **options) ⇒ Object
fast update existing data.
Constructor Details
#initialize(klass) ⇒ ModelApi
Returns a new instance of ModelApi.
7 8 9 |
# File 'lib/elasticsearch_record/model_api.rb', line 7 def initialize(klass) @klass = klass end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/elasticsearch_record/model_api.rb', line 5 def klass @klass end |
Instance Method Details
#alias_exists? ⇒ Boolean
Shortcut for alias_exists
|
# File 'lib/elasticsearch_record/model_api.rb', line 145
|
#aliases ⇒ Hash
Shortcut for aliases
|
# File 'lib/elasticsearch_record/model_api.rb', line 128
|
#backup!(to: nil, close: true) ⇒ String
Shortcut for backup_table
|
# File 'lib/elasticsearch_record/model_api.rb', line 180
|
#block! ⇒ Boolean
Shortcut to block write access on the index
|
# File 'lib/elasticsearch_record/model_api.rb', line 97
|
#bulk(data, operation = :index, refresh: true, **options) ⇒ Object
bulk handle provided data (single Hash or multiple Array
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/elasticsearch_record/model_api.rb', line 267 def bulk(data, operation = :index, refresh: true, **) data = [data] unless data.is_a?(Array) _connection.api(:core, :bulk, { index: _index_name, body: if operation == :update data.map { |item| { operation => { _id: (item[:_id].presence || item['_id']), data: { doc: item.except(:_id, '_id') } } } } else data.map { |item| { operation => { _id: (item[:_id].presence || item['_id']), data: item.except(:_id, '_id') } } } end, refresh: refresh }, "BULK #{operation.to_s.upcase}", **) end |
#clone!(target_name, **options) ⇒ Boolean
Shortcut for clone_table
|
# File 'lib/elasticsearch_record/model_api.rb', line 168
|
#close! ⇒ Boolean
Shortcut to close the opened index.
|
# File 'lib/elasticsearch_record/model_api.rb', line 89
|
#create!(force: false, copy_from: nil, if_not_exists: false, **options) ⇒ Boolean
Shortcut for create_table
|
# File 'lib/elasticsearch_record/model_api.rb', line 161
|
#delete(data, **options) ⇒ Object
fast delete data. IMPORTANT: Any 'doc'-id must by provided with underscore '_' ( +:_id+ )
253 254 255 256 257 258 259 260 261 |
# File 'lib/elasticsearch_record/model_api.rb', line 253 def delete(data, **) data = [data] unless data.is_a?(Array) if data[0].is_a?(Hash) bulk(data, :delete, **) else bulk(data.map { |id| { _id: id } }, :delete, **) end end |
#drop!(confirm: false) ⇒ Boolean
Shortcut to drop the index
|
# File 'lib/elasticsearch_record/model_api.rb', line 105
|
#exists? ⇒ Boolean
Shortcut for exists
|
# File 'lib/elasticsearch_record/model_api.rb', line 141
|
#index(data, **options) ⇒ Object
fast insert/update data. IMPORTANT: Any 'doc'-id must by provided with underscore '_' ( +:_id+ )
209 210 211 |
# File 'lib/elasticsearch_record/model_api.rb', line 209 def index(data, **) bulk(data, :index, **) end |
#insert(data, **options) ⇒ Object
fast insert new data. IMPORTANT: Any 'doc'-id must by provided with underscore '_' ( +:_id+ )
223 224 225 |
# File 'lib/elasticsearch_record/model_api.rb', line 223 def insert(data, **) bulk(data, :create, **) end |
#mapping_exists? ⇒ Boolean
Shortcut for mapping_exists
|
# File 'lib/elasticsearch_record/model_api.rb', line 153
|
#mappings ⇒ Hash
Shortcut for mappings
|
# File 'lib/elasticsearch_record/model_api.rb', line 115
|
#meta_exists? ⇒ Boolean
Shortcut for meta_exists
|
# File 'lib/elasticsearch_record/model_api.rb', line 157
|
#metas ⇒ Hash
Shortcut for metas
|
# File 'lib/elasticsearch_record/model_api.rb', line 119
|
#open! ⇒ Boolean
Shortcut to open the closed index.
|
# File 'lib/elasticsearch_record/model_api.rb', line 85
|
#refresh! ⇒ Boolean
Shortcut to refresh the index.
|
# File 'lib/elasticsearch_record/model_api.rb', line 93
|
#reindex!(target_name, **options) ⇒ Hash
Shortcut for reindex_table
|
# File 'lib/elasticsearch_record/model_api.rb', line 193
|
#rename!(target_name, timeout: nil, **options) ⇒ Object
Shortcut for rename_table
|
# File 'lib/elasticsearch_record/model_api.rb', line 174
|
#restore!(from: , timeout: nil, open: true, drop_backup: false) ⇒ Boolean
Shortcut for restore_table
|
# File 'lib/elasticsearch_record/model_api.rb', line 186
|
#schema(features = []) ⇒ Hash
Shortcut for schema
|
# File 'lib/elasticsearch_record/model_api.rb', line 136
|
#setting_exists? ⇒ Boolean
Shortcut for setting_exists
|
# File 'lib/elasticsearch_record/model_api.rb', line 149
|
#settings(flat_settings = true) ⇒ Hash
Shortcut for settings
|
# File 'lib/elasticsearch_record/model_api.rb', line 123
|
#state ⇒ Hash
Shortcut for state
|
# File 'lib/elasticsearch_record/model_api.rb', line 132
|
#truncate!(confirm: false) ⇒ Boolean
Shortcut to truncate the index
|
# File 'lib/elasticsearch_record/model_api.rb', line 110
|
#unblock! ⇒ Boolean
Shortcut to unblock all blocked accesses on the index
|
# File 'lib/elasticsearch_record/model_api.rb', line 101
|
#update(data, **options) ⇒ Object
fast update existing data. IMPORTANT: Any 'doc'-id must by provided with underscore '_' ( +:_id+ )
237 238 239 |
# File 'lib/elasticsearch_record/model_api.rb', line 237 def update(data, **) bulk(data, :update, **) end |