Module: Chewy::Type::Import::ClassMethods
- Defined in:
- lib/chewy/type/import.rb
Instance Method Summary collapse
-
#bulk(**options) ⇒ Hash
Wraps elasticsearch API bulk method, adds additional features like
bulk_size
andsuffix
. -
#compose(object, crutches = nil, fields: []) ⇒ Hash
Composes a single document from the passed object.
-
#import(*collection, **options) ⇒ true, false
Basically, one of the main methods for type.
-
#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
.
102 103 104 105 106 107 |
# File 'lib/chewy/type/import.rb', line 102 def bulk(**) error_items = BulkRequest.new(self, **).perform([:body]) Chewy.wait_for_status payload_errors(error_items) end |
#compose(object, crutches = nil, fields: []) ⇒ Hash
Composes a single document from the passed object. Uses either witchcraft or normal composing under the hood.
116 117 118 119 120 121 122 123 124 |
# File 'lib/chewy/type/import.rb', line 116 def compose(object, crutches = nil, fields: []) crutches ||= Chewy::Type::Crutch::Crutches.new self, [object] if witchcraft? && root.children.present? cauldron(fields: fields).brew(object, crutches) else root.compose(object, crutches, fields: fields) end end |
#import(*collection, **options) ⇒ true, false
Basically, one of the main methods for type. Performs any objects import to the index for a specified type. 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 depenting on the used adapter. It destroys passed objects from the index if they are not in the default type scope or marked for destruction.
It handles parent-child relationships: if the object parent_id has been changed it destroys the object and recreates it from scratch.
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 occured 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/type/import.rb', line 75 def import(*args) import_routine(*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 |
# File 'lib/chewy/type/import.rb', line 86 def import!(*args) errors = import_routine(*args) raise Chewy::ImportFailed.new(self, errors) if errors.present? true end |