Module: Chewy::Index::Import::ClassMethods
- Defined in:
- lib/chewy/index/import.rb
Instance Method Summary collapse
-
#bulk(**options) ⇒ Hash
Wraps elasticsearch API bulk method, adds additional features like ‘bulk_size` and `suffix`.
-
#compose(object, crutches = nil, fields: [], context: {}) ⇒ Hash
Composes a single document from the passed object.
-
#import(*collection, **options) ⇒ true, false
Basically, one of the main methods for an index.
-
#import!(*collection, **options) ⇒ Object
(see #import).
Instance Method Details
#bulk(**options) ⇒ Hash
Wraps elasticsearch API bulk method, adds additional features like ‘bulk_size` and `suffix`.
104 105 106 107 108 109 |
# File 'lib/chewy/index/import.rb', line 104 def bulk(**) error_items = BulkRequest.new(self, **).perform([:body]) Chewy.wait_for_status payload_errors(error_items) end |
#compose(object, crutches = nil, fields: [], context: {}) ⇒ Hash
Composes a single document from the passed object. Uses either witchcraft or normal composing under the hood.
118 119 120 121 122 123 124 125 126 |
# File 'lib/chewy/index/import.rb', line 118 def compose(object, crutches = nil, fields: [], context: {}) crutches ||= Chewy::Index::Crutch::Crutches.new self, [object], context if witchcraft? && root.children.present? cauldron(fields: fields).brew(object, crutches, context) else root.compose(object, crutches, fields: fields, context: context) end end |
#import(*collection, **options) ⇒ true, false
Basically, one of the main methods for an index. Performs any objects import to the index. Does all the objects handling routines. Performs document import by utilizing bulk API. Bulk size and objects batch size are controlled by the corresponding options.
It accepts ORM/ODM objects, PORO, hashes, ids which are used by adapter to fetch objects from the source depending on the used adapter. It destroys passed objects from the index if they are not in the default scope or marked for destruction.
It handles parent-child relationships with a join field reindexing children when the parent is reindexed.
Performs journaling if enabled: it stores all the ids of the imported objects to a specialized index. It is possible to replay particular import later to restore the data consistency.
Performs partial index update using ‘update` bulk action if any `fields` are specified. Note that if document doesn’t exist yet, an error will be raised by ES, but import catches this an errors and performs full indexing for the corresponding documents. This feature can be disabled by setting ‘update_failover` to `false`.
Utilizes ‘ActiveSupport::Notifications`, so it is possible to get imported objects later by listening to the `import_objects.chewy` queue. It is also possible to get the list of occurred errors from the payload if something went wrong.
Import can also be run in parallel using the Parallel gem functionality.
75 76 77 |
# File 'lib/chewy/index/import.rb', line 75 def import(*args) intercept_import_using_strategy(*args).blank? end |
#import!(*collection, **options) ⇒ Object
(see #import)
The only difference from #import is that it raises an exception in case of any import errors.
86 87 88 89 90 91 92 |
# File 'lib/chewy/index/import.rb', line 86 def import!(*args) errors = intercept_import_using_strategy(*args) raise Chewy::ImportFailed.new(self, errors) if errors.present? true end |