Method: Chewy::Index::Actions::ClassMethods#reset!
- Defined in:
- lib/chewy/index/actions.rb
#reset!(suffix = nil, apply_journal: true, journal: false, **import_options) ⇒ true, false Also known as: reset
Deletes, creates and imports data to the index. Returns the import result. If index name suffix is passed as the first argument - performs zero-downtime index resetting.
It also applies journal if anything was journaled during the reset.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/chewy/index/actions.rb', line 149 def reset!(suffix = nil, apply_journal: true, journal: false, **) result = if suffix.present? start_time = Time.now indexes = self.indexes - [index_name] create! suffix, alias: false general_name = index_name suffixed_name = index_name(suffix: suffix) optimize_index_settings suffixed_name result = import(**.merge( suffix: suffix, journal: journal, refresh: !Chewy.reset_disable_refresh_interval )) original_index_settings suffixed_name delete if indexes.blank? client.indices.update_aliases body: {actions: [ *indexes.map do |index| {remove: {index: index, alias: general_name}} end, {add: {index: suffixed_name, alias: general_name}} ]} client.indices.delete index: indexes if indexes.present? self.journal.apply(start_time, **) if apply_journal result else purge! import(**.merge(journal: journal)) end specification.lock! result end |