Class: Chewy::Index::Import::BulkBuilder
- Inherits:
-
Object
- Object
- Chewy::Index::Import::BulkBuilder
- Defined in:
- lib/chewy/index/import/bulk_builder.rb
Overview
This class purpose is to build ES client-acceptable bulk request body from the passed objects for index and deletion. It handles parent-child relationships as well by fetching existing documents from ES and database, taking their join field values and using it in the bulk body. If fields are passed - it creates partial update entries except for the cases when the type has parent and parent_id has been changed.
Instance Method Summary collapse
-
#bulk_body ⇒ Array<Hash>
Returns ES API-ready bulk requiest body.
-
#index_objects_by_id ⇒ Hash[String => Object]
The only purpose of this method is to cache document ids for all the passed object for index to avoid ids recalculation.
-
#initialize(index, to_index: [], delete: [], fields: []) ⇒ BulkBuilder
constructor
A new instance of BulkBuilder.
Constructor Details
#initialize(index, to_index: [], delete: [], fields: []) ⇒ BulkBuilder
Returns a new instance of BulkBuilder.
16 17 18 19 20 21 |
# File 'lib/chewy/index/import/bulk_builder.rb', line 16 def initialize(index, to_index: [], delete: [], fields: []) @index = index @to_index = to_index @delete = delete @fields = fields.map!(&:to_sym) end |
Instance Method Details
#bulk_body ⇒ Array<Hash>
Returns ES API-ready bulk requiest body.
26 27 28 29 30 31 32 |
# File 'lib/chewy/index/import/bulk_builder.rb', line 26 def bulk_body populate_cache @bulk_body ||= @to_index.flat_map(&method(:index_entry)).concat( @delete.flat_map(&method(:delete_entry)) ).uniq end |
#index_objects_by_id ⇒ Hash[String => Object]
The only purpose of this method is to cache document ids for all the passed object for index to avoid ids recalculation.
38 39 40 |
# File 'lib/chewy/index/import/bulk_builder.rb', line 38 def index_objects_by_id @index_objects_by_id ||= index_object_ids.invert.stringify_keys! end |