How to create “Hello World” node client of Elastic-Search in Java

Hi Group,

I have seen the docs at https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/node-client.htm but am not able to create a node client.

Java file containing the code:

import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.NodeBuilder;

public class EsRoutingNodeClient
{
private static final String ZEN_DISCOVERY_UNICAST_HOSTS = "["10.10.10.10:9200"]"; // Used an actual ES master node's IP here
private static final String ES_PATH_HOME = "/Users/appuser/work/software/elasticsearch/dummy-path-home/";
private static final String ES_CLUSTER_NAME = "my-cluster";
private Client client;

private void createEsClient ()
{
    Settings settings = Settings.settingsBuilder()
            .put("http.enabled", false)
            .put("discovery.zen.ping.multicast.enabled", false)
            .put("discovery.zen.ping.unicast.hosts", ZEN_DISCOVERY_UNICAST_HOSTS)
            .put("discovery.zen.minimum_master_nodes", 1)
            .put("path.home", ES_PATH_HOME)
            .build();
    client =
            NodeBuilder.nodeBuilder()
            .settings(settings)
            .clusterName(ES_CLUSTER_NAME)
            .data(false)
            .client(true)
            .node().client();
}

public EsRoutingNodeClient ()
{
    createEsClient();
}

public static void main (String args[])
{
    new EsRoutingNodeClient();
}

}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

4.0.0
examples
es-node-client
0.0.3-SNAPSHOT
jar
es-node-client

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>



org.elasticsearch
elasticsearch
2.2.0





org.apache.maven.plugins
maven-shade-plugin
2.4.3



package

shade




org.slf4j:
com.esotericsoftware.kryo:kryo:






examples.EsRoutingNodeClient








I run it as follows:

mvn clean package
java -jar target/es-node-client-0.0.3-SNAPSHOT.jar

Exception I get is:

  1. Error injecting constructor, java.lang.IllegalStateException: This is a proxy used to support circular references involving constructors. The object we're proxying is not constructed yet. Please wait until after injection has completed to use this object.
    at org.elasticsearch.node.service.NodeService.(Unknown Source)
    while locating org.elasticsearch.node.service.NodeService
    for parameter 5 at org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction.(Unknown Source)
    while locating org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction
    for parameter 2 at org.elasticsearch.cluster.InternalClusterInfoService.(Unknown Source)

Caused by: java.lang.IllegalStateException: This is a proxy used to support circular references involving constructors. The object we're proxying is not constructed yet. Please wait until after injection has completed to use this object.
at org.elasticsearch.common.inject.internal.ConstructionContext$DelegatingInvocationHandler.invoke(ConstructionContext.java:103)
.... more lines
at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:152)
at examples.EsRoutingNodeClient.createEsClient(EsRoutingNodeClient.java:30)
at examples.EsRoutingNodeClient.(EsRoutingNodeClient.java:46)
at examples.EsRoutingNodeClient.main(EsRoutingNodeClient.java:51)