title: org.elasticsearch.action.UnavailableShardsException
body: <p>I face the similar problem like <a href="http://elasticsearch-users.115913.n3.nabble.com/New-to-Elastic-Search-I-get-this-exception-org-elasticsearch-action-UnavailableShardsException-td3244381.html" rel="nofollow">http://elasticsearch-users.115913.n3.nabble.com/New-to-Elastic-Search-I-get-this-exception-org-elasticsearch-action-UnavailableShardsException-td3244381.html</a>.</p>
  
  <p>I have a master node with config:</p>
  
  <pre><code>cluster.name: geocoding
  node.name: "node1"
  node.master: true
  node.data: false
  index.number_of_shards: 5
  index.number_of_replicas: 0
  discovery.zen.ping.multicast.enabled: false
  discovery.zen.ping.unicast.hosts: ["localhost"]
  </code></pre>
  
  <p>and a data node with config:</p>
  
  <pre><code>cluster.name: geocoding
  node.name: "node2"
  node.master: false
  node.data: true
  index.number_of_shards: 5
  index.number_of_replicas: 0
  discovery.zen.ping.multicast.enabled: false
  discovery.zen.ping.unicast.hosts: ["localhost"]
  </code></pre>
  
  <p>Started both master &amp; data node , running on 9200 &amp; 9201 resp.</p>
  
  <p>When i connecting for made index (using the following source), I met err(org.elasticsearch.action.UnavailableShardsException).</p>
  
  <p>Source code:</p>
  
  <pre><code>ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
      builder.put("node.client", true);
      builder.put("node.data", false);
      builder.put("node.name", "node3");
      builder.put("cluster.name", "geocoding");
      builder.put("discovery.zen.ping.multicast.enabled", "false");
      builder.put("discovery.zen.ping.unicast.hosts", "localhost");
      builder.build();
      Node node = NodeBuilder.nodeBuilder().settings(builder).node();
      client = node.client();
  print(client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet());
  </code></pre>
  
  <p>It prints:</p>
  
  <pre><code>{
    "cluster_name" : "geocoding",
    "status" : "red",
    "timed_out" : true,
    "number_of_nodes" : 3,
    "number_of_data_nodes" : 1,
    "active_primary_shards" : 4,
    "active_shards" : 4,
    "relocating_shards" : 0,
    "initializing_shards" : 0,
    "unassigned_shards" : 16
  }
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Edited:
  @AndreiStefan: 
  curl -XGET localhost:9200/_cat/shards?v</p>
  
  <pre><code>index  shard prirep state      docs store ip              node  
  india  2     p      UNASSIGNED                                  
  india  2     r      UNASSIGNED                                  
  india  0     p      UNASSIGNED                                  
  india  0     r      UNASSIGNED                                  
  india  3     p      UNASSIGNED                                  
  india  3     r      UNASSIGNED                                  
  india  1     p      UNASSIGNED                                  
  india  1     r      UNASSIGNED                                  
  india  4     p      UNASSIGNED                                  
  india  4     r      UNASSIGNED                                  
  mytest 4     p      UNASSIGNED                                  
  mytest 4     r      UNASSIGNED                                  
  mytest 0     p      STARTED       0  115b &lt;my ip&gt; node2 
  mytest 0     r      UNASSIGNED                                  
  mytest 3     p      STARTED       1 2.6kb &lt;my ip&gt; node2 
  mytest 3     r      UNASSIGNED                                  
  mytest 1     p      STARTED       0  115b &lt;my ip&gt; node2 
  mytest 1     r      UNASSIGNED                                  
  mytest 2     p      STARTED       0  115b &lt;my ip&gt; node2 
  mytest 2     r      UNASSIGNED 
  </code></pre>
  
  <p>Exception detail:
  org.elasticsearch.action.UnavailableShardsException: [india][4] Primary shard is not active or isn't assigned is a known node. Timeout: [1m], request: index {[x][y][1], source[{"message":"a",}]}</p>
  
  <p>Edited:
  Full source:</p>
  
  <pre><code>HashMap&lt;String, String&gt; documentMap = new HashMap();
              String id = "1";
              String indexName = "india";
              String indexType = "address";
  
              ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
              builder.put("node.client", true);
              builder.put("node.data", false);
              builder.put("node.name", "node3");
              builder.put("cluster.name", "geocoding");
              builder.put("discovery.zen.ping.multicast.enabled", "false");
              builder.put("discovery.zen.ping.unicast.hosts", "localhost");
              builder.build();
  
              Node node = NodeBuilder.nodeBuilder().settings(builder).node();
              Client client = node.client();
              XContentBuilder contentBuilder = XContentFactory.jsonBuilder().startObject();
  
              Iterator&lt;String&gt; keys = documentMap.keySet().iterator();
              while (keys.hasNext()) {
                  String key = keys.next();
                  contentBuilder.field(key, documentMap.get(key));
              }
              contentBuilder.endObject();
  
              IndexResponse response = client.prepareIndex(indexName, indexType, id).setSource(contentBuilder).execute().actionGet();
  </code></pre>