# Monitor Elastic Search Re-Index Progress

**URL:** https://discuss.elastic.co/t/monitor-elastic-search-re-index-progress/128014
**Category:** Elasticsearch
**Created:** [April 13, 2018, 5:16pm UTC](https://discuss.elastic.co/t/monitor-elastic-search-re-index-progress/128014 "2018-04-13T17:16:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![cawoodm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cawoodm/32/14083_2.png) [@cawoodm](https://discuss.elastic.co/u/cawoodm)
#### Post date: [April 13, 2018, 5:16pm UTC](https://discuss.elastic.co/t/monitor-elastic-search-re-index-progress/128014/1 "2018-04-13T17:16:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [April 13, 2018, 8:58pm UTC](https://discuss.elastic.co/t/monitor-elastic-search-re-index-progress/128014/2 "2018-04-13T20:58:18Z")

</div>

> [@cawoodm](#):
>
> Also elastic people: the API kinda sucks.

Did you try [grouping by](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/tasks.html#_task_grouping) `parents` or `none`? Perhaps, these format would be more suitable for your needs.

---

<div class="post-metadata">

### Author: ![cawoodm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cawoodm/32/14083_2.png) [@cawoodm](https://discuss.elastic.co/u/cawoodm)
#### Post date: [April 16, 2018, 9:25am UTC](https://discuss.elastic.co/t/monitor-elastic-search-re-index-progress/128014/3 "2018-04-16T09:25:20Z")

</div>

We still see the following structure returned:

```
GET /_tasks?detailed=true&actions=*reindex&group_by=parents
{
    "tasks": {
        "6tgOP8JVSmai0c0uR_Co7g:609579": {
            "node": "6tgOP8JVSmai0c0uR_Co7g",
            "id": 609579,
            ...
        }
    }
}

```

I don't know about other languages but this is hard to parse in PowerShell. Ideally you would have an array:

```
{
    "tasks": [
        "6tgOP8JVSmai0c0uR_Co7g:609579": {
        ...
        }
    ]
}

```

Which you can simply iterate or access with `tasks[0]`.

---

<div class="post-metadata">

### Author: ![cawoodm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cawoodm/32/14083_2.png) [@cawoodm](https://discuss.elastic.co/u/cawoodm)
#### Post date: [April 16, 2018, 9:27am UTC](https://discuss.elastic.co/t/monitor-elastic-search-re-index-progress/128014/4 "2018-04-16T09:27:00Z")

</div>

Ah, I stand corrected. When we use `group_by=none` we get an array!

```
{
    "tasks": [
        {
            "node": "6tgOP8JVSmai0c0uR_Co7g",
            "id": 609579,
            "type": "transport",
            "action": "indices:data/write/reindex",
            "start_time_in_millis": 1523870243676,
            "running_time_in_nanos": 540175604651,
            "cancellable": true,
            "headers": {}
        }
    ]
}

```

Thanks Igor!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 14, 2018, 9:27am UTC](https://discuss.elastic.co/t/monitor-elastic-search-re-index-progress/128014/5 "2018-05-14T09:27:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
