Skip to content

Instantly share code, notes, and snippets.

@sstults
Created March 6, 2018 22:29
Show Gist options
  • Save sstults/9295e383807caec2b7d919a9e6f20972 to your computer and use it in GitHub Desktop.
Save sstults/9295e383807caec2b7d919a9e6f20972 to your computer and use it in GitHub Desktop.
Quick and sloppy script to clear out unused fields from Solr's schema API
import json
from urllib.parse import urlencode
from urllib.request import Request, urlopen
solr_url = 'http://localhost:8983/solr/gettingstarted/schema'
luke_file = open('luke-json-output.json', 'r')
luke_json = json.load(luke_file)
luke_file.close()
for field in luke_json['fields']:
if 'docs' not in luke_json['fields'][field]:
post_fields = {'delete-field': {"name": field}}
request = Request(solr_url, urlencode(post_fields).encode())
urlopen(request).read().decode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment