json - Java ElasticSearch example using TransportCilent -
The following code describes the communication between Java and elastic search - using the transport client. When I run, I'm sorry. Elastic Search Any clear example for the Java flexible shirt will be given or someone can help me get the solution.
public static client function () {settings setting = ImmutableSettings.settingsBuilder (). Put ("cluster.name", "localtestsearch"). Build (); Client = new transport client (); Customer = client.addTransportAddress (new InetSocketTransportAddress ("localhost", 9300)); Return customer; } Public static zero main (string [] args) {System.out.println ("in the main method"); Try {System.out.println ("in the attempt block"); Client Client = New Transport Client (.addTransportAddress) (New InetSocketTransportAddress ("Localhost", 9300)); Println ("connected"); Client.close (); Settings settings = ImmutableSettings.settingsBuilder (). Input ("client.transport.sniff", true) .build (); TransportClient client1 = new transport client (settings); Org.elasticsearch.node.Node Node = Nodbilder (). Node (); System.out.println ("node" + node); Client Client = node.client (); System.out.println ("node to client client" + client); Node.close (); System.out.println ("node clause"); } Hold (Exception pre) {ex.printStackTrace (); }}}}
import org.elasticsearch.client.transport. TransportClient; Import org.elasticsearch.common.transport.InetSocketTransportAddress; Public class test {public static zero main (string [] args) {transport client client = new transport client (); (String host: client.settings). GetAsArray ("transport.client.initial_nodes")) {int port = 9300; // or parse with host string ... string [] splitHost = host.split (":", 2); If (splitHost.length == 2) {host = splitHost [0]; Port = integer PRIIENT (split host [1]); } Client.addTransportAddress (new InetSocketTransportAddress (host, port)); } // ...}}
Comments
Post a Comment