Java code to Elasticsearch

Hi All,

Please help me with the java code to send the data to elasticsearch. I went through the post for same , found below code but not helping with problem statement-
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.health.ClusterIndexHealth;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.;
import org.elasticsearch.
;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class Test {
public static void main(String[] argv) throws UnknownHostException{

        //create client !!!Make sure keep settings empty if your cluster is the 
        //same as the one you defined in your elasticsearch.yml file
        //Plus, port here(9300)must be different from your http port(9200)
	 Settings settings = Settings.Builder
			    .put("cluster.name", "ElasticSearchClusterName")
			    .build();
        TransportClient client = new PreBuiltTransportClient(settings)
        		.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
        //get data
        GetResponse response = client.prepareGet("twitter", "tweet", "1").execute().actionGet();

       //output
        System.out.println(response.getSourceAsString());

        client.close(); 
        } }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.