title: IndexPrimaryShardNotAllocatedException error while trying to close an elasticsearch cluster
body: <p>After installing elasticsearch on my machine using <a href="https://gist.github.com/wingdspur/2026107" rel="nofollow">https://gist.github.com/wingdspur/2026107</a> which starts an elasticsearch cluster at <code>http://localhost:9200</code>, I am trying to create an index with settings and used this code:</p>
  
  <pre><code>  search_indices.create index: 'test'
    search_indices.refresh index: 'test'
    search_indices.close index: 'test'
    search_indices.put_settings(index: 'test', **my_index_settings)
    search_indices.put_mapping(index: 'test', **my_mapping_settings)
    search_indices.open index: 'test'
  </code></pre>
  
  <p>Where</p>
  
  <pre><code>search_indices = Elasticsearch::Client.new({host: 'http://localhost:9200'}).indices
  # this module comes from the elasticsearch-ruby gem
  </code></pre>
  
  <p>When I execute this code, I get an error when I try to execute the 'close' method (line 3 above)</p>
  
  <pre><code>Elasticsearch::Transport::Transport::Errors::Conflict:
     [409] {"error":"IndexPrimaryShardNotAllocatedException[[test_1] primary not allocated post api]","status":409}
  </code></pre>
  
  <p>I have tried adding the refresh method (line 2 above) which sometimes work and sometimes doesn't, I have a feeling that 'sometimes working' means I'm doing something wrong. Thanks for the help!</p>