Created
August 19, 2020 21:19
-
-
Save zarazan/f43c457ecdd7e0a509e9d09b3a228456 to your computer and use it in GitHub Desktop.
Revisions
-
zarazan created this gist
Aug 19, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ def remove_deleted_units_from_search(facility_id) search_params = { facility_id: facility_id, models: 'Unit', _source: ['id'] } response = Er::Client.new.facility_search(search_params) response_ids = response['results'].map { |result| result['_source']['id'] } current_unit_ids = Facility.find(facility_id).units.where(deleted: false).pluck(:id) unit_ids_to_remove = response_ids - current_unit_ids unit_ids_to_remove.each do |unit_id| Unit.searchkick_index.remove(Unit.new(id: unit_id)) puts "Removing unit ID #{unit_id} from search" end end remove_deleted_units_from_search(5698)