# Can I clarify how admin api works for creating an index?

**URL:** <https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099>\
**Category:** Elasticsearch\
**Created:** [March 15, 2011, 3:25pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099 "2011-03-15T15:25:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [March 15, 2011, 3:25pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/1 "2011-03-15T15:25:48Z")

</div>

We are testing to see if [https://github.com/elasticsearch/elasticsearch/issues/#issue/726](https://github.com/elasticsearch/elasticsearch/issues/#issue/726)  
is fixed.  
Our test still fails - but differently now. Instead of it hanging, we  
get an error.  
"Failed to execute phase [query\_fetch], total failure; shardFailures  
{[_na_][testindex][0]: No active shards}"

We are creating the index thus:

CreateIndexRequest request = createIndexRequest(indexName);  
request.settings("{number\_of\_shards : 1 }");  
client.admin().indices().create(request).actionGet();

Is the index created & ready when "actionGet" method returns?

When we try and search this index immediately after creating it  
(theres nothing in the index - we just expect zero results) we get the  
above error.

Out of curiosity, we also added the following code, after creating the  
index.  
This makes it happy - but not sure if thats just because the call  
introduces sufficient delay - or whether its what we need to do.

client.admin()  
.cluster()  
.health(  
clusterHealthRequest()  
.waitForYellowStatus() // we only have 1 shard - hence  
wait for yellow  
.timeout(timeValueSeconds(60))  
)  
.actionGet();

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 15, 2011, 3:32pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/2 "2011-03-15T15:32:14Z")

</div>

Hi Zohar

> Is the index created & ready when "actionGet" method returns?

As I understand it (and I stand under correction), a create index call  
is async, so it is not ready when actionGet returns.

> Out of curiosity, we also added the following code, after creating the  
> index.  
> This makes it happy - but not sure if thats just because the call  
> introduces sufficient delay - or whether its what we need to do.

Not a coincidence. Using a wait\_for\_status call is the correct thing to  
do - exactly what it is designed for.

clint

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 15, 2011, 4:02pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/3 "2011-03-15T16:02:49Z")

</div>

There are three different things associated with creating an index. The first is adding it to the cluster metadata, then creating it on each relevant node, and finally, allocating shards to nodes that resulted from the index creation.

The create index API makes sure that the index provided is correct (analyzers are found, mappings are correct), waits for the _index_ itself to be created on the relevant nodes, but does not wait for the shards to be allocated.

The cluster health API, with the wait\_for..., allows to wait till shards are allocated. Some APIs wait (till a timeout) if a shard is not allocated yet (like the index API), some don't, like search.

-shay.banon  
On Tuesday, March 15, 2011 at 5:32 PM, Clinton Gormley wrote:

> Hi Zohar
> 
> > Is the index created & ready when "actionGet" method returns?
> 
> As I understand it (and I stand under correction), a create index call  
> is async, so it is not ready when actionGet returns.
> 
> > Out of curiosity, we also added the following code, after creating the  
> > index.  
> > This makes it happy - but not sure if thats just because the call  
> > introduces sufficient delay - or whether its what we need to do.
> 
> Not a coincidence. Using a wait\_for\_status call is the correct thing to  
> do - exactly what it is designed for.
> 
> clint

---

<div class="post-metadata">

**Author:** ![mooky](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@mooky](https://discuss.elastic.co/u/mooky)\
**Post date:** [March 15, 2011, 5:46pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/4 "2011-03-15T17:46:48Z")

</div>

> > The create index API makes sure that the index provided is correct  
> > (analyzers are found, mappings are correct), waits for the _index_ itself to  
> > be created on the relevant nodes, but does not wait for the shards to be allocated.

What's the rationale for not waiting for the shards to be allocated?  
(just for my education/understanding)

> > Some APIs wait (till a timeout) if a shard is not allocated yet (like the index API), some don't, like search.

Again, just for my education/understanding, why doesn't the search  
wait?

-Nick

On Mar 15, 4:02 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> There are three different things associated with creating an index. The first is adding it to the cluster metadata, then creating it on each relevant node, and finally, allocating shards to nodes that resulted from the index creation.
> 
> The create index API makes sure that the index provided is correct (analyzers are found, mappings are correct), waits for the _index_ itself to be created on the relevant nodes, but does not wait for the shards to be allocated.
> 
> The cluster health API, with the wait\_for..., allows to wait till shards are allocated. Some APIs wait (till a timeout) if a shard is not allocated yet (like the index API), some don't, like search.
> 
> -shay.banon
> 
> On Tuesday, March 15, 2011 at 5:32 PM, Clinton Gormley wrote:
> 
> > Hi Zohar
> 
> > > Is the index created & ready when "actionGet" method returns?
> 
> > As I understand it (and I stand under correction), a create index call  
> > is async, so it is not ready when actionGet returns.
> 
> > > Out of curiosity, we also added the following code, after creating the  
> > > index.  
> > > This makes it happy - but not sure if thats just because the call  
> > > introduces sufficient delay - or whether its what we need to do.
> 
> > Not a coincidence. Using a wait\_for\_status call is the correct thing to  
> > do - exactly what it is designed for.
> 
> > clint

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 15, 2011, 7:25pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/5 "2011-03-15T19:25:42Z")

</div>

No specific reason except for the complexity involved in implementing it, and the fact that it mainly when doing testing.  
On Tuesday, March 15, 2011 at 7:46 PM, Mooky wrote:

> > > The create index API makes sure that the index provided is correct  
> > > (analyzers are found, mappings are correct), waits for the _index_ itself to  
> > > be created on the relevant nodes, but does not wait for the shards to be allocated.
> 
> What's the rationale for not waiting for the shards to be allocated?  
> (just for my education/understanding)
> 
> > > Some APIs wait (till a timeout) if a shard is not allocated yet (like the index API), some don't, like search.
> 
> Again, just for my education/understanding, why doesn't the search  
> wait?
> 
> -Nick
> 
> On Mar 15, 4:02 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > There are three different things associated with creating an index. The first is adding it to the cluster metadata, then creating it on each relevant node, and finally, allocating shards to nodes that resulted from the index creation.
> > 
> > The create index API makes sure that the index provided is correct (analyzers are found, mappings are correct), waits for the _index_ itself to be created on the relevant nodes, but does not wait for the shards to be allocated.
> > 
> > The cluster health API, with the wait\_for..., allows to wait till shards are allocated. Some APIs wait (till a timeout) if a shard is not allocated yet (like the index API), some don't, like search.
> > 
> > -shay.banon
> > 
> > On Tuesday, March 15, 2011 at 5:32 PM, Clinton Gormley wrote:
> > 
> > > Hi Zohar
> > 
> > > > Is the index created & ready when "actionGet" method returns?
> > 
> > > As I understand it (and I stand under correction), a create index call  
> > > is async, so it is not ready when actionGet returns.
> > 
> > > > Out of curiosity, we also added the following code, after creating the  
> > > > index.  
> > > > This makes it happy - but not sure if thats just because the call  
> > > > introduces sufficient delay - or whether its what we need to do.
> > 
> > > Not a coincidence. Using a wait\_for\_status call is the correct thing to  
> > > do - exactly what it is designed for.
> > 
> > > clint

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 15, 2011, 7:28pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/6 "2011-03-15T19:28:57Z")

</div>

Also, you might actually want to get search response when not all shards are available.  
On Tuesday, March 15, 2011 at 9:25 PM, Shay Banon wrote:

> No specific reason except for the complexity involved in implementing it, and the fact that it mainly when doing testing.  
> On Tuesday, March 15, 2011 at 7:46 PM, Mooky wrote:
> 
> > > > The create index API makes sure that the index provided is correct  
> > > > (analyzers are found, mappings are correct), waits for the _index_ itself to  
> > > > be created on the relevant nodes, but does not wait for the shards to be allocated.
> > 
> > What's the rationale for not waiting for the shards to be allocated?  
> > (just for my education/understanding)
> > 
> > > > Some APIs wait (till a timeout) if a shard is not allocated yet (like the index API), some don't, like search.
> > 
> > Again, just for my education/understanding, why doesn't the search  
> > wait?
> > 
> > -Nick
> > 
> > On Mar 15, 4:02 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > There are three different things associated with creating an index. The first is adding it to the cluster metadata, then creating it on each relevant node, and finally, allocating shards to nodes that resulted from the index creation.
> > > 
> > > The create index API makes sure that the index provided is correct (analyzers are found, mappings are correct), waits for the _index_ itself to be created on the relevant nodes, but does not wait for the shards to be allocated.
> > > 
> > > The cluster health API, with the wait\_for..., allows to wait till shards are allocated. Some APIs wait (till a timeout) if a shard is not allocated yet (like the index API), some don't, like search.
> > > 
> > > -shay.banon
> > > 
> > > On Tuesday, March 15, 2011 at 5:32 PM, Clinton Gormley wrote:
> > > 
> > > > Hi Zohar
> > > 
> > > > > Is the index created & ready when "actionGet" method returns?
> > > 
> > > > As I understand it (and I stand under correction), a create index call  
> > > > is async, so it is not ready when actionGet returns.
> > > 
> > > > > Out of curiosity, we also added the following code, after creating the  
> > > > > index.  
> > > > > This makes it happy - but not sure if thats just because the call  
> > > > > introduces sufficient delay - or whether its what we need to do.
> > > 
> > > > Not a coincidence. Using a wait\_for\_status call is the correct thing to  
> > > > do - exactly what it is designed for.
> > > 
> > > > clint

---

<div class="post-metadata">

**Author:** ![mooky](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@mooky](https://discuss.elastic.co/u/mooky)\
**Post date:** [March 15, 2011, 11:34pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/7 "2011-03-15T23:34:01Z")

</div>

Ah, yep, true.

On 15 March 2011 19:28, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> Also, you might actually want to get search response when not all shards are  
> available.

---

<div class="post-metadata">

**Author:** ![mooky](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@mooky](https://discuss.elastic.co/u/mooky)\
**Post date:** [March 15, 2011, 11:37pm UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/8 "2011-03-15T23:37:55Z")

</div>

Fair enough. Thanks.

Yeah, I think in our situation it showed up as a test that kept  
failing intermittently.... just a timing thing (initially it was  
hanging)

-Nick

On 15 March 2011 19:25, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> No specific reason except for the complexity involved in implementing it,  
> and the fact that it mainly when doing testing.
> 
> On Tuesday, March 15, 2011 at 7:46 PM, Mooky wrote:
> 
> The create index API makes sure that the index provided is correct  
> (analyzers are found, mappings are correct), waits for the _index_ itself to  
> be created on the relevant nodes, but does not wait for the shards to be  
> allocated.
> 
> What's the rationale for not waiting for the shards to be allocated?  
> (just for my education/understanding)
> 
> Some APIs wait (till a timeout) if a shard is not allocated yet (like the  
> index API), some don't, like search.
> 
> Again, just for my education/understanding, why doesn't the search  
> wait?
> 
> -Nick
> 
> On Mar 15, 4:02 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> There are three different things associated with creating an index. The  
> first is adding it to the cluster metadata, then creating it on each  
> relevant node, and finally, allocating shards to nodes that resulted from  
> the index creation.
> 
> The create index API makes sure that the index provided is correct  
> (analyzers are found, mappings are correct), waits for the _index_ itself to  
> be created on the relevant nodes, but does not wait for the shards to be  
> allocated.
> 
> The cluster health API, with the wait\_for..., allows to wait till shards are  
> allocated. Some APIs wait (till a timeout) if a shard is not allocated yet  
> (like the index API), some don't, like search.
> 
> -shay.banon
> 
> On Tuesday, March 15, 2011 at 5:32 PM, Clinton Gormley wrote:
> 
> Hi Zohar
> 
> Is the index created & ready when "actionGet" method returns?
> 
> As I understand it (and I stand under correction), a create index call  
> is async, so it is not ready when actionGet returns.
> 
> Out of curiosity, we also added the following code, after creating the  
> index.  
> This makes it happy - but not sure if thats just because the call  
> introduces sufficient delay - or whether its what we need to do.
> 
> Not a coincidence. Using a wait\_for\_status call is the correct thing to  
> do - exactly what it is designed for.
> 
> clint

---

<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:** [July 6, 2017, 4:10am UTC](https://discuss.elastic.co/t/can-i-clarify-how-admin-api-works-for-creating-an-index/4099/9 "2017-07-06T04:10:00Z")

</div>


