Remove unassigned Graylog2 index/shards with Bash in a loop
<p>There were some disk issues on a Graylog2 server I use for debug logs. There are unassigned shards now:</p>

<pre><code>curl -XGET http://host:9200/_cat/shards

graylog_292 1 p STARTED    751733  648.4mb 127.0.1.1 Doctor Leery 
graylog_292 1 r UNASSIGNED                                        
graylog_292 2 p STARTED    756663  653.2mb 127.0.1.1 Doctor Leery 
graylog_292 2 r UNASSIGNED                                        
graylog_290 0 p STARTED    299059  257.2mb 127.0.1.1 Doctor Leery 
graylog_290 0 r UNASSIGNED                                        
graylog_290 3 p STARTED    298759  257.1mb 127.0.1.1 Doctor Leery 
graylog_290 3 r UNASSIGNED                                        
graylog_290 1 p STARTED    298314  257.3mb 127.0.1.1 Doctor Leery 
graylog_290 1 r UNASSIGNED                                        
graylog_290 2 p STARTED    297722  257.1mb 127.0.1.1 Doctor Leery 
graylog_290 2 r UNASSIGNED 
....
</code></pre>

<p>It's over 400 shards. I can delete them without data loss, because it's a single node setup. In order to do this I need to loop over the index (graylog_xxx) and over the shard (1,2,...).</p>

<p>How do I loop over this (2 variables) with Bash? There are 2 variables for the deletion API call, which I need to replace (afaik):</p>

<pre><code>curl -XPOST 'host:9200/_cluster/reroute' -d '{
        "commands" : [ {
              "allocate" : {
                  "index" : "$index", 
                  "shard" : $shard, 
                  "node" : "Doctor Leery", 
                  "allow_primary" : true
              }
            }
        ]
    }'
</code></pre>

<p>What also bothers me about this is, that the unassigned shards have no node. But in the API call I need to specify one.</p>