Elasticsearch Client Java Simple Code application

Source: Internet
Author: User
Package Com.kele,xuebi;
Import java.net.InetAddress;

Import java.net.UnknownHostException;
Import Org.elasticsearch.action.index.IndexResponse;
Import org.elasticsearch.client.Client;
Import org.elasticsearch.client.transport.TransportClient;
Import org.elasticsearch.common.settings.Settings;

Import org.elasticsearch.common.transport.InetSocketTransportAddress;  public class CreateIndex {public static void main (string[] args) throws Unknownhostexception {//TODO auto-generated Method stub//client Configuration reference official Information link//https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport -client.html//my-application This name is the same as the cluster parameter name configured in/opt/elasticsearch-2.2.0/config/elasticsearch.yml cluster.name:my-a

		Pplication Settings settings = Settings.settingsbuilder (). Put ("Cluster.name", "my-application"). Build (); Client client = Transportclient.builder (). settings (Settings). Build (). addtransportaddresses (New Inetsockettransportaddress (Inetaddress.getbyname ("BigdaTaspark "), 9300). addtransportaddresses (New inetsockettransportaddress inetaddress.getbyname (" Bigdatacloud "),
		
		9300)). Addtransportaddresses (New Inetsockettransportaddress (Inetaddress.getbyname ("Bigdatastorm"), 9300));
		
		Indexresponse actionget = Client.prepareindex ("shuiguo101", "Friut", "1"). SetSource (). Execute (). Actionget ();
		System.out.println (Actionget);
			
	Client.close ();
 }

}

This thing is not easy ...


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.