2016-10-08 6 views
0

Powershell 2.0を使用して、特定の接頭辞で始まるSolrコアの削除を自動化する方法はありますか?たとえば、「some_prefix」で始まるすべてのコアを削除したいとします。私はSolrの4.10.1を使用して、次のAPI呼び出しでコアを削除したいのです:Powershellを使用して接頭辞で始まるSolrコアを削除する

http://localhost:8983/solr/admin/cores?action=UNLOAD&deleteIndex=true&deleteInstanceDir=true&core=some_prefix_etc 

答えて

0

このスクリプトは動作します:構文はリストにコアを抽出する方法を

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." 

thisをで見ますコアを削除するためのSolr UNLOAD APIオプションのthisオプションがあります。

関連する問題