Skip to content

Instantly share code, notes, and snippets.

@dkinzer
Created June 27, 2024 14:03
Show Gist options
  • Save dkinzer/d94bd142763ebd3fa1e4af53d405c345 to your computer and use it in GitHub Desktop.
Save dkinzer/d94bd142763ebd3fa1e4af53d405c345 to your computer and use it in GitHub Desktop.
Delete aliases in a solr collection
#! /usr/bin/env ruby
require 'httparty'
solr_url = "https://#{ENV["SOLRCLOUD_HOST"]}/solr/admin/collections"
auth = { username: ENV["SOLR_AUTH_USER"], password: ENV["SOLR_AUTH_PASSWORD"] }
resp = HTTParty.get(solr_url, basic_auth: auth, query: { action: "LIST" })
matcher = ARGV.join || "thisisnotarealcollectionname"
collections = resp["collections"].select { |c| c.match?(/#{matcher}/) }
puts "We are going to delete the following collections, are you OK with that (y|N)?
#{collections.join("\n")}"
delete = $stdin.gets.chomp
if delete == "Y" || delete == "y" || delete == "yes"
puts "Deleting the collections:"
collections.each { |c| puts HTTParty.get(solr_url, basic_auth: auth, query: { action: "DELETE", name: c }) }
else
puts "OK, we are not deleting the collections"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment