This commit is contained in:
Stefan Hardegger
2026-07-20 12:17:51 +02:00
parent dca6ddadd5
commit f7eabe1761
2 changed files with 15 additions and 16 deletions

View File

@@ -1401,23 +1401,21 @@ public class SolrService {
for (String coreName : coreNames) {
try {
logger.info("Recreating Solr core: {}", coreName);
logger.info("Clearing Lucene index for core: {}", coreName);
// Unload the core and delete all index data
// Unload the core and delete only the Lucene index files.
// deleteIndex=true removes data/index/ only; conf/ and core.properties are preserved.
// deleteDataDir=false keeps the data directory so the core can be reloaded in place.
org.apache.solr.client.solrj.request.CoreAdminRequest.unloadCore(
coreName, true, true, solrClient);
logger.info("Unloaded core: {}", coreName);
coreName, true, false, solrClient);
logger.info("Unloaded core (index deleted): {}", coreName);
// Recreate the core from its configset (same name as the core)
org.apache.solr.client.solrj.request.CoreAdminRequest.Create createReq =
new org.apache.solr.client.solrj.request.CoreAdminRequest.Create();
createReq.setCoreName(coreName);
createReq.setConfigSet(coreName);
createReq.process(solrClient);
logger.info("Recreated core: {}", coreName);
// Reload the core from its existing conf/ directory with a fresh empty index.
org.apache.solr.client.solrj.request.CoreAdminRequest.reloadCore(coreName, solrClient);
logger.info("Reloaded core with fresh index: {}", coreName);
} catch (SolrServerException e) {
logger.warn("Could not recreate core {} (may not exist yet): {}", coreName, e.getMessage());
logger.warn("Could not clear/reload core {} (may not exist yet): {}", coreName, e.getMessage());
}
}
}