When re-indexing large indexes it can take some time. There is a Reindex API which helps monitor the progress of a re-index and I've written a PowerShell Script which uses this to display a progress bar. In the hopes that it may help others I post it here:
UPDATE: The following is the optimized code based on feedback below:
Clear
$ESHost = "http://yourESHostHere:9200"
$tasks = Invoke-WebRequest -Uri "$ESHost/_tasks?detailed=true&actions=*reindex&group_by=none" | ConvertFrom-Json
if (-not $tasks -or -not $tasks.tasks) {return "No re-index tasks found!"}
# Take the first task
$taskid = $tasks.tasks[0].node + ":" + $tasks.tasks[0].id
"Polling Task $taskid..."
$Done = $false
do {
try {
$task = Invoke-RestMethod -Uri "$ESHost/_tasks/$taskid"
} catch {
# 404 means task is complete
if ($_.Exception.Response.StatusCode.value__ -eq 404) {$Done = $true}
else {Write-Error $_}
}
if ($task.completed -or $Done) {
"Done!"
} else {
$tot = $task.task.status.total
$prog = $task.task.status.created
$per = [Math]::round(100 * $prog / $tot)
Write-Progress -PercentComplete $per -Activity "$per% Re-indexing" -Status "$prog / $tot documents created"
}
Sleep -Seconds 1
} while (-not $Done)
Note, it just takes the first active re-index task and monitors that. There's no support currently for monitoring multiple tasks.