Ayub Malik Ayub Malik - 1 year ago 74
Java Question

Elasticsearch local node client NPE when creating index in java test

I am using elasticsearch (v2.3.2/Windows 7) local node to create an index in a java test which is throwing an null pointer exception.

The test code is as follows:

CreateIndexResponse response = esClient.admin().indices().prepareCreate("mytestindex")
.put("number_of_replicas", 0)
.put("number_of_shards", 1))

I have verified esClient is created by spring and is not null. The code to create the client is:

public Client localElasticsearchClient() {

Settings settings = Settings.settingsBuilder()
.put("path.home", "/tmp/elasticsearch")
.put("path.data", "/tmp/elasticsearch")

return NodeBuilder.nodeBuilder()


The stacktrace is as follows:

at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction.<init>(TransportMasterNodeAction.java:129)
at org.elasticsearch.action.support.master.TransportMasterNodeAction.doExecute(TransportMasterNodeAction.java:107)
at org.elasticsearch.action.support.master.TransportMasterNodeAction.doExecute(TransportMasterNodeAction.java:51)
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:137)
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:85)
at org.elasticsearch.client.node.NodeClient.doExecute(NodeClient.java:58)

I saw something here about it but there was no info on how to correct it.

Answer Source

Actually the answer was implicitly given in this link

I was not calling node.start() method i.e.

return NodeBuilder.nodeBuilder()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download