Java api fails to create index


(Harish Kulkarni) #1

I am able to add a document to an index using curl.
But trying to add document using java api gives below error
Primary shard is not active or isn't assigned to a known node. Timeout: [1m],

Here is my client code
Node node = nodeBuilder().clusterName("pzap").client(true).node()
Client client = node.client()
I have tried without client(true) but it gives same error.

IndexRequest indexRequest = new IndexRequest("megacorp2", "Inventory", inv.id.toString());
indexRequest.source(sb.toString());
IndexResponse response = client.index(indexRequest).actionGet();

I have created megacorp2 index using curl


(David Pilato) #2

I'm sure that if you try to index a doc using curl, you will get the same error.

So the problem is not your code but your cluster.
Check logs. Check cluster health...


(Jettro Coenradie) #3

I would also check if your client is actually connected to your cluster. Is your cluster running on localhost? Does it use the default port 9300. Is the cluster name right?

You could try the cluster health from the client perspective:

ClusterHealthResponse clusterIndexHealths = client.admin().cluster().prepareHealth().get();

(Harish Kulkarni) #4

This was fixed by using TransportClient.

Settings s = ImmutableSettings.settingsBuilder()
.put("cluster.name","pzap")
.build()
TransportClient client = new TransportClient(s)
client.addTransportAddress(new InetSocketTransportAddress(
"localhost",
9300)


(system) #5