2016-10-08 3 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 옵션이 있습니다.