# Error when create an index in two hosts

**URL:** <https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528>\
**Category:** Elasticsearch\
**Created:** [October 11, 2017, 9:58am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528 "2017-10-11T09:58:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chanpiseth\_Ros](https://avatars.discourse-cdn.com/v4/letter/c/c4cdca/32.png) [@Chanpiseth\_Ros](https://discuss.elastic.co/u/Chanpiseth_Ros)\
**Post date:** [October 11, 2017, 9:58am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528/1 "2017-10-11T09:58:55Z")

</div>

Hi Teams, i have an error when i try to create an index in two hosts with php code, and this is an error message:

> Exception : {"error":"IndexAlreadyExistsException[[sample] already exists]","status":400}

And this is my code php:

> $hosts = [  
> 1 =\> '[http://elasticsearch:9200](http://elasticsearch:9200)',  
> 2 =\> '[http://10.10.10.20:9200](http://10.10.10.20:9200)'  
> ];  
> ClientBuilder::indices()-\>create($hosts);

Can anyone help me?

---

<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:** [October 11, 2017, 10:12am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528/2 "2017-10-11T10:12:39Z")

</div>

I don't understand PHP I'm afraid. What is it suppose to run behind the scene?

I don't see where the `political` index name is coming from in your code. Are you sure it's complete?

---

<div class="post-metadata">

**Author:** ![A\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_b/32/17104_2.png) [@A\_B](https://discuss.elastic.co/u/A_B)\
**Post date:** [October 11, 2017, 10:46am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528/3 "2017-10-11T10:46:22Z")

</div>

A few questions just to clarify stuff...

1. Are you trying to write to two hosts in the same cluster or are they separate clusters?
2. What do you want to achieve by creating the indices on two different hosts?

---

<div class="post-metadata">

**Author:** ![Chanpiseth\_Ros](https://avatars.discourse-cdn.com/v4/letter/c/c4cdca/32.png) [@Chanpiseth\_Ros](https://discuss.elastic.co/u/Chanpiseth_Ros)\
**Post date:** [October 12, 2017, 1:01am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528/4 "2017-10-12T01:01:00Z")

</div>

Yes, i want to achieve by crating the indices on two different hosts.

---

<div class="post-metadata">

**Author:** ![zqc0512](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zqc0512/32/32141_2.png) [@zqc0512](https://discuss.elastic.co/u/zqc0512)\
**Post date:** [October 12, 2017, 3:27am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528/5 "2017-10-12T03:27:06Z")

</div>

the cluster output the same already exists see is or not?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 12, 2017, 5:24am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528/6 "2017-10-12T05:24:44Z")

</div>

Indices are created per cluster, not host, so if these two nodes belong to the same cluster you only need to send the request to one of the nodes. Elasticsearch will then create the index and distribute shards across all nodes in the cluster.

---

<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:** [November 9, 2017, 5:24am UTC](https://discuss.elastic.co/t/error-when-create-an-index-in-two-hosts/103528/7 "2017-11-09T05:24:45Z")

</div>

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