有没有办法使用Powershell 2.0自动删除以给定前缀开头的Solr核心?例如,我想删除所有以" some_prefix"开头的核心。我正在使用Solr 4.10.1,并希望使用以下API调用删除核心:
http://localhost:8983/solr/admin/cores?action=UNLOAD&deleteIndex=true&deleteInstanceDir=true&core=some_prefix_etc
答案 0 :(得分:1)
此脚本可以使用:
param ($prefix = $(throw "-prefix is required"))
$client = (New-Object System.Net.WebClient)
[xml]$coresXML = $client.DownloadString("http://localhost:8983/solr/admin/cores")
$cores = $coresXML.response.lst[2].lst | % {$_.name}
$success = 0
$error = 0
foreach ($core in $cores) {
if ($core.StartsWith($prefix)) {
$url = "http://localhost:8983/solr/admin/cores?action=UNLOAD&deleteIndex=true&deleteInstanceDir=true&core=$core"
write-host "Deleting $core :"
$client.DownloadString($url)
if ($?) {$success++}
else $error++
}
}
write-host "Deleted $success cores. Had $error errors."