Skip to content

Instantly share code, notes, and snippets.

@zarazan
Created August 19, 2020 21:19
Show Gist options
  • Select an option

  • Save zarazan/f43c457ecdd7e0a509e9d09b3a228456 to your computer and use it in GitHub Desktop.

Select an option

Save zarazan/f43c457ecdd7e0a509e9d09b3a228456 to your computer and use it in GitHub Desktop.

Revisions

  1. zarazan created this gist Aug 19, 2020.
    13 changes: 13 additions & 0 deletions remove_deleted_units.rb
    Original 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)