# PrimaryNotStartedActionException with JAVA API

**URL:** <https://discuss.elastic.co/t/primarynotstartedactionexception-with-java-api/2881>\
**Category:** Elasticsearch\
**Created:** [March 31, 2010, 7:47am UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-with-java-api/2881 "2010-03-31T07:47:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HubertChang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubertchang/32/3352_2.png) [@HubertChang](https://discuss.elastic.co/u/HubertChang)\
**Post date:** [March 31, 2010, 7:47am UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-with-java-api/2881/1 "2010-03-31T07:47:15Z")

</div>

My elasticsearch.in.sh is:  
JAVA\_OPTS="   
-Xms128M   
-Xmx1G   
-Djline.enabled=true   
-Djava.net.preferIPv4Stack=true   
-XX:+AggressiveOpts   
-XX:+UseParNewGC   
-XX:+UseConcMarkSweepGC   
-XX:+CMSParallelRemarkEnabled   
-XX:+HeapDumpOnOutOfMemoryError   
-Dgateway.fs.location=/datastore/es/   
-Dpath.logs=/datastore/es/logs/"  
No extra config is added in elasticsearch.yml.

After elasticsearch started on the single node, I run:  
curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{name:"8888"}'  
The response:  
{"ok":true,"\_index":"twitter","\_type":"tweet","\_id":"1"}

My code(in groovy):

import org.elasticsearch.client.Client  
import org.elasticsearch.server.Server  
import org.elasticsearch.server.ServerBuilder  
import org.elasticsearch.util.settings.ImmutableSettings  
import org.elasticsearch.action.index.IndexResponse  
import org.elasticsearch.action.index.IndexRequest  
Server server  
try {  
server = new ServerBuilder().  
settings(ImmutableSettings.settingsBuilder().  
put("node.data", false).  
put("node.local", false)  
).server()  
} catch (Exception e) {  
println(e.getMessage())  
server.close()  
}  
Client client = server.client()  
println "index one message."  
IndexResponse response = client.index(new IndexRequest("twitter")  
.type("tweet")  
.id("88")  
.source("{name:'HubertChang'}")).actionGet()  
println "close the server."  
server.close()

The output:  
index one message.  
Caught: org.elasticsearch.action.PrimaryNotStartedActionException: [twitter][3] Timeout waiting for [1m]

What's wrong with this?

---

<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 31, 2010, 7:52am UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-with-java-api/2881/2 "2010-03-31T07:52:06Z")

</div>

Can you try and add -Djava.net.preferIPv4Stack=true to your client side as  
well? Check in the output (logs/console) if the client node you started in  
groovy manages to connect to the cluster.

-shay.banon

On Wed, Mar 31, 2010 at 10:47 AM, HubertChang [huixiu@gmail.com](mailto:huixiu@gmail.com) wrote:

> My elasticsearch.in.sh is:  
> JAVA\_OPTS="   
> -Xms128M   
> -Xmx1G   
> -Djline.enabled=true   
> -Djava.net.preferIPv4Stack=true   
> -XX:+AggressiveOpts   
> -XX:+UseParNewGC   
> -XX:+UseConcMarkSweepGC   
> -XX:+CMSParallelRemarkEnabled   
> -XX:+HeapDumpOnOutOfMemoryError   
> -Dgateway.fs.location=/datastore/es/   
> -Dpath.logs=/datastore/es/logs/"  
> No extra config is added in elasticsearch.yml.
> 
> After elasticsearch started on the single node, I run:  
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{name:"8888"}'  
> The response:  
> {"ok":true,"\_index":"twitter","\_type":"tweet","\_id":"1"}
> 
> My code(in groovy):
> 
> import org.elasticsearch.client.Client  
> import org.elasticsearch.server.Server  
> import org.elasticsearch.server.ServerBuilder  
> import org.elasticsearch.util.settings.ImmutableSettings  
> import org.elasticsearch.action.index.IndexResponse  
> import org.elasticsearch.action.index.IndexRequest  
> Server server  
> try {  
> server = new ServerBuilder().  
> settings(ImmutableSettings.settingsBuilder().  
> put("node.data", false).  
> put("node.local", false)  
> ).server()  
> } catch (Exception e) {  
> println(e.getMessage())  
> server.close()  
> return  
> }  
> Client client = server.client()  
> println "index one message."  
> IndexResponse response = client.index(new IndexRequest("twitter")  
> .type("tweet")  
> .id("88")  
> .source("{name:'HubertChang'}")).actionGet()  
> println "close the server."  
> server.close()
> 
> The output:  
> index one message.  
> Caught: org.elasticsearch.action.PrimaryNotStartedActionException:  
> [twitter][3] Timeout waiting for [1m]
> 
> What's wrong with this?
> 
> --  
> View this message in context:  
> [http://n3.nabble.com/PrimaryNotStartedActionException-with-JAVA-API-tp687867p687867.html](http://n3.nabble.com/PrimaryNotStartedActionException-with-JAVA-API-tp687867p687867.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![HubertChang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubertchang/32/3352_2.png) [@HubertChang](https://discuss.elastic.co/u/HubertChang)\
**Post date:** [March 31, 2010, 8:01am UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-with-java-api/2881/3 "2010-03-31T08:01:13Z")

</div>

After add "-Djava.net.preferIPv4Stack=true",  
Output is:  
index one message.  
Caught: org.elasticsearch.transport.RemoteTransportException: [Jonas Harrow][inet[/192.168.56.1:9300]][indices/index/shard/index]

Replace "{name:'HubertChang'}" with '{name:"HubertChang"}', everyting is ok!

Thanks!

---

<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:24am UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-with-java-api/2881/4 "2017-07-06T04:24:58Z")

</div>


