Waiting for Primary Shard Allocation before closing an Index

Hey,

I am wondering if there is a way to wait for the Primary Shard Allocation
before I try to close an Index with the Java API. My usecase is to create
an index and close it immediately afterwards.
If I run both Java statements in a direct sequence I get often the
Exception: class
org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException
Is there any way to wait for the primary shard allocation when I try to
close the Index? Something like setRefresh(true) when indexing new
documents?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/52f4dee3-5fa9-46e3-a824-513c04afd60e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I can't think of a good reason you'd want to close immediately but if you
really do the simplest thing is to wait for the cluster health to turn
yellow. You can be more careful and just wait for the index health to turn
yellow but I don't know if there is a simple wait api for that. There is
for cluster state:

$ curl -XGET 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s'

You can run the same thing in Java code, I'm sure.

On Wed, Nov 27, 2013 at 9:48 AM, Stefan Meiwald st.meiwald@gmail.comwrote:

Hey,

I am wondering if there is a way to wait for the Primary Shard Allocation
before I try to close an Index with the Java API. My usecase is to create
an index and close it immediately afterwards.
If I run both Java statements in a direct sequence I get often the
Exception: class
org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException
Is there any way to wait for the primary shard allocation when I try to
close the Index? Something like setRefresh(true) when indexing new
documents?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/52f4dee3-5fa9-46e3-a824-513c04afd60e%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3s%2B2MGEfbjKX9YGFqpNvUVcmDFrUsDaqtZjqwDLP%2Batg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Same for me. I don't see a reason (may be unit test?) to do that.

Wait for yellow in Java could be done like this:

node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

HTH

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr

Le 27 novembre 2013 at 15:53:34, Nikolas Everett (nik9000@gmail.com) a écrit:

I can't think of a good reason you'd want to close immediately but if you really do the simplest thing is to wait for the cluster health to turn yellow. You can be more careful and just wait for the index health to turn yellow but I don't know if there is a simple wait api for that. There is for cluster state:

$ curl -XGET 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s'
You can run the same thing in Java code, I'm sure.

On Wed, Nov 27, 2013 at 9:48 AM, Stefan Meiwald st.meiwald@gmail.com wrote:
Hey,

I am wondering if there is a way to wait for the Primary Shard Allocation before I try to close an Index with the Java API. My usecase is to create an index and close it immediately afterwards.
If I run both Java statements in a direct sequence I get often the Exception: class org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException
Is there any way to wait for the primary shard allocation when I try to close the Index? Something like setRefresh(true) when indexing new documents?

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/52f4dee3-5fa9-46e3-a824-513c04afd60e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3s%2B2MGEfbjKX9YGFqpNvUVcmDFrUsDaqtZjqwDLP%2Batg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.5296080d.519b500d.3e14%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks for that workaround.
Actually I want to block writing for that index for the first 10 minutes
and afterwards allow it.
I just found additional Index Settings that could help me out with that
issue without closing and opening the index:

index.blocks.read
index.blocks.write

Am Mittwoch, 27. November 2013 15:48:12 UTC+1 schrieb Stefan Meiwald:

Hey,

I am wondering if there is a way to wait for the Primary Shard Allocation
before I try to close an Index with the Java API. My usecase is to create
an index and close it immediately afterwards.
If I run both Java statements in a direct sequence I get often the
Exception: class
org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException
Is there any way to wait for the primary shard allocation when I try to
close the Index? Something like setRefresh(true) when indexing new
documents?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/00d5112a-40c3-44ae-ad02-85921dbb4d70%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Why not creating the index only when you will start need it?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr

Le 27 novembre 2013 at 16:05:32, Stefan Meiwald (st.meiwald@gmail.com) a écrit:

Thanks for that workaround.
Actually I want to block writing for that index for the first 10 minutes and afterwards allow it.
I just found additional Index Settings that could help me out with that issue without closing and opening the index:

index.blocks.read
index.blocks.write
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html

Am Mittwoch, 27. November 2013 15:48:12 UTC+1 schrieb Stefan Meiwald:
Hey,

I am wondering if there is a way to wait for the Primary Shard Allocation before I try to close an Index with the Java API. My usecase is to create an index and close it immediately afterwards.
If I run both Java statements in a direct sequence I get often the Exception: class org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException
Is there any way to wait for the primary shard allocation when I try to close the Index? Something like setRefresh(true) when indexing new documents?

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/00d5112a-40c3-44ae-ad02-85921dbb4d70%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.52960c96.257130a3.3e14%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/groups/opt_out.

I thought I could get around another Index/datastore that holds
"placeholder" indices for the first 10 minutes but it seems that this would
be the best solution maybe.

Am Mittwoch, 27. November 2013 15:48:12 UTC+1 schrieb Stefan Meiwald:

Hey,

I am wondering if there is a way to wait for the Primary Shard Allocation
before I try to close an Index with the Java API. My usecase is to create
an index and close it immediately afterwards.
If I run both Java statements in a direct sequence I get often the
Exception: class
org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException
Is there any way to wait for the primary shard allocation when I try to
close the Index? Something like setRefresh(true) when indexing new
documents?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6a3f2681-d7c2-4fd6-a98a-90762b09c0d0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I've found that refreshing the index after I create it and before I close
it solves this issue. This may not be 'best practice'

On Wednesday, November 27, 2013 7:23:26 AM UTC-8, Stefan Meiwald wrote:

I thought I could get around another Index/datastore that holds
"placeholder" indices for the first 10 minutes but it seems that this would
be the best solution maybe.

Am Mittwoch, 27. November 2013 15:48:12 UTC+1 schrieb Stefan Meiwald:

Hey,

I am wondering if there is a way to wait for the Primary Shard Allocation
before I try to close an Index with the Java API. My usecase is to create
an index and close it immediately afterwards.
If I run both Java statements in a direct sequence I get often the
Exception: class
org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException
Is there any way to wait for the primary shard allocation when I try to
close the Index? Something like setRefresh(true) when indexing new
documents?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/37e84108-ebe6-4cb5-8fe3-6922d6434315%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.