Hi there,
I'm using the native client (TransportClient) and I'm running the following
code:
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",
"elasticsearch").build(); TransportClient client = new
TransportClient(settings); client.addTransportAddress(new
InetSocketTransportAddress("localhost", 9300)); Settings indexSettings =
ImmutableSettings.settingsBuilder().put("number_of_shards", 4)
.put("number_of_replicas", 3).build(); CreateIndexRequestBuilder
createIndexBuilder = client.admin().indices().prepareCreate("newindex");
createIndexBuilder.setSettings(indexSettings); CreateIndexResponse
createIndexResponse = createIndexBuilder.execute().actionGet();
System.out.printf("acknowledged: %s%n",
createIndexResponse.acknowledged()); GetRequestBuilder get =
client.prepareGet(); get.setIndex("newindex"); get.setType("mytype");
get.setId("myid"); try { GetResponse response =
get.execute().actionGet(1000); System.out.printf("exists: %s%n",
response.exists()); } catch (Throwable ex) { ex.printStackTrace(); }
When I execute it for the first time on a fresh node, I always get the
following error:
acknowledged: true
org.elasticsearch.action.NoShardAvailableActionException: [newindex][0] No
shard available for [[newindex][mytype][myid]: routing [null]]
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.perform(TransportShardSingleOperationAction.java:139)
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.start(TransportShardSingleOperationAction.java:124)
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:71)
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:46)
at
org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:61)
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$TransportHandler.messageReceived(TransportShardSingleOperationAction.java:217)
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$TransportHandler.messageReceived(TransportShardSingleOperationAction.java:199)
...
When I delete the index and run this code again, it runs just fine (and
prints exists:false obviously).
When I execute the GetRequest a little bit later, it runs just fine too.
How do I wait for the CreateIndexRequest to be really completed before
starting other processing on the new index?
Jaap
--