# How to write into multiple data node via PHP API

**URL:** <https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106>\
**Category:** Elasticsearch\
**Created:** [May 25, 2017, 11:07am UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106 "2017-05-25T11:07:17Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 11:07am UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/1 "2017-05-25T11:07:17Z")

</div>

Hello

i am using PHP API to write data into 2 nodes of the master node in single cluster

how i can save the specific data into specific node via PHP REST API

is there any setting to define in the REST API that Data will save in particular node

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2017, 11:51am UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/2 "2017-05-25T11:51:45Z")

</div>

Not clear what you want to do but basically when you write data, you write it within an index.  
The index by default can be allocated anywhere on your cluster.

If you want to allocate your index only on a specific set of machines, then you can tag them and use then shard allocation filtering. See [https://www.elastic.co/guide/en/elasticsearch/reference/5.4/shard-allocation-filtering.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/shard-allocation-filtering.html)

But I'm curious on the reason you think that might be a good idea in a 2 nodes context. (BTW 3 nodes should be the minimal for production to avoid split brain issues)

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 12:02pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/3 "2017-05-25T12:02:40Z")

</div>

hello

here is my structure

Master Node = 1  
data node = 2

Index = 2

i want to write the first index only in first data node and second only in second data node

but the post of the node is 9301 and 9302 that not allowed to access via REST API

REST API only accept 9200- 9300

hope you understand now

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2017, 1:02pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/4 "2017-05-25T13:02:59Z")

</div>

Yes. Still I don't understand why you want to do that and not let elasticsearch distribute the indices on the cluster.

Anyway look at [https://www.elastic.co/guide/en/elasticsearch/reference/5.4/shard-allocation-filtering.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/shard-allocation-filtering.html)

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 1:04pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/5 "2017-05-25T13:04:24Z")

</div>

hello i understand that

thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2017, 1:21pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/6 "2017-05-25T13:21:11Z")

</div>

Hum... I think I understand your question.

So you have 2 nodes running on the same machine?  
Then you want to send index requests to one of the node and other index requests to the other node. Is that right?

If so, just send requests either to:

- [http://127.0.0.1:9200](http://127.0.0.1:9200)

or

- [http://127.0.0.1:9201](http://127.0.0.1:9201)

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 1:23pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/7 "2017-05-25T13:23:40Z")

</div>

you are right boss

now you understand me

i read your document to create the index and assign that to node via attributes of shard allocation filters

that i am trying now

so do you think i am on the right track ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2017, 1:41pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/8 "2017-05-25T13:41:28Z")

</div>

Yes. May be.

I mean that you did not tell **WHY** you want to do that. What problem you think you are trying to solve here?

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 1:42pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/9 "2017-05-25T13:42:27Z")

</div>

now i am facing issue

`{"error":{"root_cause":[{"type":"unavailable_shards_exception","reason":"[node_2][0] primary shard is not active Timeout: [1m], request: [BulkShardRequest [[node_2][0]] containing [index {[node_2][test_document][test_document_1], source[{\"testField\":\"abc\"}]}]]"}],"type":"unavailable_shards_exception","reason":"[node_2][0] primary shard is not active Timeout: [1m], request: [BulkShardRequest [[node_2][0]] containing [index {[node_2][test_document][test_document_1], source[{\"testField\":\"abc\"}]}]]"},"status":503}`

when i am creating document in the shard of index

here is my nodes log

```
{
  "cluster_name" : "cs",
  "version" : 4,
  "state_uuid" : "aEflY06dQBW4DZdYG2RuUQ",
  "master_node" : "xs6GUEkCQ9GE9xhUfQPk-A",
  "blocks" : { },
  "nodes" : {
    "H9ROPBHaT5GvR_DKj42W6w" : {
      "name" : "node_2",
      "ephemeral_id" : "xLFEyG7GRaKmIjkq7LFXuw",
      "transport_address" : "127.0.0.1:9301",
      "attributes" : {
        "size" : "big",
        "rack" : "node_2"
      }
    },
    "xs6GUEkCQ9GE9xhUfQPk-A" : {
      "name" : "node_1",
      "ephemeral_id" : "Eq5BP4mxTj6LIRQ4sFw_mw",
      "transport_address" : "127.0.0.1:9300",
      "attributes" : { }
    }
  },
  "metadata" : {
    "cluster_uuid" : "7JtoIEjOTSW9BdPj4sRlSQ",
    "templates" : { },
    "indices" : {
      "node_2" : {
        "state" : "open",
        "settings" : {
          "index" : {
            "routing" : {
              "allocation" : {
                "include" : {
                  "_name" : "node_2",
                  "size" : "big",
                  "rack" : "node_2"
                }
              }
            },
            "number_of_shards" : "5",
            "provided_name" : "node_2",
            "creation_date" : "1495718156182",
            "number_of_replicas" : "1",
            "uuid" : "k0K7KBonQc6lhr4-rngoXQ",
            "version" : {
              "created" : "5040099"
            }
          }
        },
        "mappings" : { },
        "aliases" : [],
        "primary_terms" : {
          "0" : 0,
          "1" : 0,
          "2" : 0,
          "3" : 0,
          "4" : 0
        },
        "in_sync_allocations" : {
          "2" : [],
          "3" : [],
          "1" : [],
          "4" : [],
          "0" : []
        }
      }
    },
    "index-graveyard" : {
      "tombstones" : []
    }
  },
  "routing_table" : {
    "indices" : {
      "node_2" : {
        "shards" : {
         
          "1" : [
            {
              "state" : "UNASSIGNED",
              "primary" : true,
              "node" : null,
              "relocating_node" : null,
              "shard" : 1,
              "index" : "node_2",
              "recovery_source" : {
                "type" : "EMPTY_STORE"
              },
              "unassigned_info" : {
                "reason" : "INDEX_CREATED",
                "at" : "2017-05-25T13:15:56.274Z",
                "delayed" : false,
                "allocation_status" : "deciders_no"
              }
            },
            {
              "state" : "UNASSIGNED",
              "primary" : false,
              "node" : null,
              "relocating_node" : null,
              "shard" : 1,
              "index" : "node_2",
              "recovery_source" : {
                "type" : "PEER"
              },
              "unassigned_info" : {
                "reason" : "INDEX_CREATED",
                "at" : "2017-05-25T13:15:56.274Z",
                "delayed" : false,
                "allocation_status" : "no_attempt"
              }
            }
          ],
         
          ]
        }
      }
    }
  },
  
    "nodes" : {
      "H9ROPBHaT5GvR_DKj42W6w" : []
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 1:43pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/10 "2017-05-25T13:43:46Z")

</div>

> [@dadoonet](#):
>
> I mean that you did not tell WHY you want to do that. What problem you think you are trying to solve here?

when i told you that i want to create the multiple nodes in the server because i want to give test for few clients in free

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2017, 1:59pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/11 "2017-05-25T13:59:57Z")

</div>

Just create one index per use case in the same node. You don't need multiple nodes and complicate things IMO.

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 3:30pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/12 "2017-05-25T15:30:23Z")

</div>

ok but what is solution of error just let me know

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2017, 3:46pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/13 "2017-05-25T15:46:42Z")

</div>

May be you removed one node and you don't have replicas so no replica has been promoted.

Hard to say without knowing what you are doing.

But again you should really take advices that we are giving on this list seriously. Specifically I think that you have little experience with elasticsearch and you don't know yet all the internals.  
If I'm right with this statement I'd encourage you reading [https://www.elastic.co/guide/en/elasticsearch/guide/current/getting-started.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/getting-started.html) to get a better understanding of what is happening behind the scene.  
Specifically this chapter: [https://www.elastic.co/guide/en/elasticsearch/guide/current/distributed-docs.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/distributed-docs.html)

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 25, 2017, 3:57pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/14 "2017-05-25T15:57:45Z")

</div>

> [@dadoonet](#):
>
> replicas

i already send you the log

here is code that i am running

$hosts = [  
'127.0.0.1:9200'  
];  
$client = ClientBuilder::create() // Instantiate a new ClientBuilder  
-\>setHosts($hosts) // Set the hosts  
-\>build();  
$params = [  
'index' =\> 'node\_2',  
'type' =\> 'test\_document',  
'id' =\> 'test\_document\_1',  
'body' =\> ['testField' =\> 'abc']  
];

```
	// Document will be indexed to my_index/my_type/my_id
	$response = $client->index($params);
   
	echo "<pre>";       
	print_r($response);
	exit;
    echo "<pre>";
	print_r($client);
	exit;

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2017, 9:58pm UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/15 "2017-05-25T21:58:43Z")

</div>

That's useless. Sorry I can't help.

---

<div class="post-metadata">

**Author:** ![pjayramkumar](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@pjayramkumar](https://discuss.elastic.co/u/pjayramkumar)\
**Post date:** [May 26, 2017, 4:49am UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/16 "2017-05-26T04:49:11Z")

</div>

thanks to support me so far

i used code from your document and if that is useless then i think you have to update your document as well

---

<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:** [June 23, 2017, 4:49am UTC](https://discuss.elastic.co/t/how-to-write-into-multiple-data-node-via-php-api/87106/17 "2017-06-23T04:49:56Z")

</div>

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