Created
August 19, 2020 21:19
-
-
Save zarazan/f43c457ecdd7e0a509e9d09b3a228456 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment