Skip to content

Instantly share code, notes, and snippets.

@rpong
Last active April 7, 2020 14:28
Show Gist options
  • Save rpong/22c8e64bbb29c351f015 to your computer and use it in GitHub Desktop.
Save rpong/22c8e64bbb29c351f015 to your computer and use it in GitHub Desktop.
optimize all cores in a given solr instance. Sample Usage: ./optimizeSolr.py http://solr1:8970
#! /usr/bin/env python
# Sample Usage: ./optimizeSolr.py http://solr1:8970
import xml.etree.ElementTree as ET;
import requests;
import time;
import sys;
if len(sys.argv) > 1 :
rootSolrUrl = sys.argv[1];
r = requests.get(rootSolrUrl + '/solr/admin/cores');
root = ET.fromstring(r.content);
for child in root[3]:
coreName = child.get('name');
rd = requests.get(rootSolrUrl+'/solr/' + coreName + '/update?optimize=true&waitFlush=true&wt=json&_=' + str(int(time.time())));
print('core: ' + coreName + ' optimize response: ' + rd.content);
else:
print "A valid Solr Admin URL is required";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment