# PrimaryNotStartedActionException using the Java APIs

**URL:** <https://discuss.elastic.co/t/primarynotstartedactionexception-using-the-java-apis/2878>\
**Category:** Elasticsearch\
**Created:** [March 30, 2010, 12:13pm UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-using-the-java-apis/2878 "2010-03-30T12:13:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Castagna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paolo_castagna/32/3347_2.png) [@Paolo\_Castagna](https://discuss.elastic.co/u/Paolo_Castagna)\
**Post date:** [March 30, 2010, 12:13pm UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-using-the-java-apis/2878/1 "2010-03-30T12:13:08Z")

</div>

Hi,  
first of all, thanks for the "beauty" you put into ElasticSearch.  
I am an absolute beginner with ElasticSearch, so forgive me if I  
ask trivial questions (but I did not find the answer on this list  
or on the documentation).

I am using ElasticSearch v0.5.1 with an empty configuration file.  
I am running a single/local node and learning how to use the Java  
API to interact with it.

Everything works fine with:

Server server = serverBuilder().settings(settingsBuilder()).server();

But, if I try to set build the server setting node.data to false:

Server server = serverBuilder().settings(settingsBuilder()  
.put("node.data", false))  
.server();

I have this exception when I try to add something to an index:

* * *

## Exception in thread "main" org.elasticsearch.action.PrimaryNotStartedActionException: [twitter][2] Timeout waiting for [1m] at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$4.onTimeout(TransportShardReplicationOperationAction.java:301) at org.elasticsearch.cluster.service.InternalClusterService$1$1.run(InternalClusterService.java:96) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)

IndexResponse response = client.index(indexRequest("twitter")  
.operationThreaded(true)  
.type("tweet")  
.id("1")  
.source(jsonBuilder()  
.startObject()  
.field("user", "kimchy")  
.field("postDate", new Date())  
.field("message", "trying out Elastic Search")  
.endObject()  
)).actionGet();

I am able to perform operations using the REST APIs.

Or, create an index with the Java APIs but when I try to add a document  
to the index I see the exception above.

Am I doing something wrong?

Paolo

---

<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 30, 2010, 3:54pm UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-using-the-java-apis/2878/2 "2010-03-30T15:54:38Z")

</div>

Not sure that I fully understand. Is the server you start the only one you  
have in the cluster? If you set it with node.data set to false, then there  
will be no node/server to allocated the indices to.

If it is not, and you started other instances of elasticsearch, then it  
might be a discovery problem where the embedded server you started can't  
discover the rest of the cluster. It should print in the console/logs if it  
discovered or not. If it did not, try and pass the following system  
property: -Djava.net.preferIPv4Stack=true (I really hope to get read of this  
soon).

-shay.banon

On Tue, Mar 30, 2010 at 3:13 PM, Paolo Castagna \<  
[castagna.lists@googlemail.com](mailto:castagna.lists@googlemail.com)\> wrote:

> Hi,  
> first of all, thanks for the "beauty" you put into Elasticsearch.  
> I am an absolute beginner with Elasticsearch, so forgive me if I  
> ask trivial questions (but I did not find the answer on this list  
> or on the documentation).
> 
> I am using Elasticsearch v0.5.1 with an empty configuration file.  
> I am running a single/local node and learning how to use the Java  
> API to interact with it.
> 
> Everything works fine with:
> 
> Server server = serverBuilder().settings(settingsBuilder()).server();
> 
> But, if I try to set build the server setting node.data to false:
> 
> Server server = serverBuilder().settings(settingsBuilder()  
> .put("node.data", false))  
> .server();
> 
> I have this exception when I try to add something to an index:
> 
> * * *
> 
> ## Exception in thread "main" org.elasticsearch.action.PrimaryNotStartedActionException: [twitter][2] Timeout waiting for [1m] at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$4.onTimeout(TransportShardReplicationOperationAction.java:301) at org.elasticsearch.cluster.service.InternalClusterService$1$1.run(InternalClusterService.java:96) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)
> 
> IndexResponse response = client.index(indexRequest("twitter")  
> .operationThreaded(true)  
> .type("tweet")  
> .id("1")  
> .source(jsonBuilder()  
> .startObject()  
> .field("user", "kimchy")  
> .field("postDate", new Date())  
> .field("message", "trying out Elastic Search")  
> .endObject()  
> )).actionGet();
> 
> I am able to perform operations using the REST APIs.
> 
> Or, create an index with the Java APIs but when I try to add a document  
> to the index I see the exception above.
> 
> Am I doing something wrong?
> 
> Paolo

---

<div class="post-metadata">

**Author:** ![Paolo\_Castagna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paolo_castagna/32/3347_2.png) [@Paolo\_Castagna](https://discuss.elastic.co/u/Paolo_Castagna)\
**Post date:** [March 30, 2010, 4:30pm UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-using-the-java-apis/2878/3 "2010-03-30T16:30:40Z")

</div>

Shay Banon wrote:

> Not sure that I fully understand. Is the server you start the only one  
> you have in the cluster? If you set it with node.data set to false, then  
> there will be no node/server to allocated the indices to.

No, the server I start is not the only one I have in the cluster.  
I start another one on the same machine using bin/elasticsearch.

> If it is not, and you started other instances of elasticsearch, then it  
> might be a discovery problem where the embedded server you started can't  
> discover the rest of the cluster. It should print in the console/logs if  
> it discovered or not. If it did not, try and pass the following system  
> property: -Djava.net.preferIPv4Stack=true (I really hope to get read of  
> this soon).

Yes, this worked. I need to use -Djava.net.preferIPv4Stack=true when  
I start bin/elasticsearch and when I execute the code which is using  
the Java APIs.

Can you explain me this issue/problem?

Is it because of IPv6 and IPv4 are enabled on the same network  
interface?

Thanks,  
Paolo

---

<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 30, 2010, 7:39pm UTC](https://discuss.elastic.co/t/primarynotstartedactionexception-using-the-java-apis/2878/4 "2010-03-30T19:39:49Z")

</div>

On Tue, Mar 30, 2010 at 7:30 PM, Paolo Castagna \<  
[castagna.lists@googlemail.com](mailto:castagna.lists@googlemail.com)\> wrote:

> Shay Banon wrote:
> 
> > Not sure that I fully understand. Is the server you start the only one you  
> > have in the cluster? If you set it with node.data set to false, then there  
> > will be no node/server to allocated the indices to.
> 
> No, the server I start is not the only one I have in the cluster.  
> I start another one on the same machine using bin/elasticsearch.
> 
> If it is not, and you started other instances of elasticsearch, then it
> 
> > might be a discovery problem where the embedded server you started can't  
> > discover the rest of the cluster. It should print in the console/logs if it  
> > discovered or not. If it did not, try and pass the following system  
> > property: -Djava.net.preferIPv4Stack=true (I really hope to get read of this  
> > soon).
> 
> Yes, this worked. I need to use -Djava.net.preferIPv4Stack=true when  
> I start bin/elasticsearch and when I execute the code which is using  
> the Java APIs.
> 
> Can you explain me this issue/problem?
> 
> Is it because of IPv6 and IPv4 are enabled on the same network  
> interface?

Yes, there are problems with the jgroups discovery module when not  
explicitly setting it. The bin/elasticsearch script sets it automatically,  
so any client needs to set it as well. I hope to remove the need for this  
once I upgrade to the next version of jgroups.

> Thanks,  
> Paolo

---

<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-using-the-java-apis/2878/5 "2017-07-06T04:24:59Z")

</div>


