How to determine if a connection has been established with elasticsearch + Java API?

1.3k views Asked by At

I'm very new to elasticsearch and the Java API. How do I determine if I've established a successful connection to elasticsearch with the API? I'd normally expect a response from the server...

Code

Client client = new TransportClient()
        .addTransportAddress(new InetSocketTransportAddress("localhost", 9300))
        .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

The node name is set to Test and I'm getting the following out of Eclipse

Nov 18, 2014 5:29:04 PM org.elasticsearch.plugins.PluginsService <init>
INFO: [Hannibal King] loaded [], sites []

I'm not seeing anything on the elasticsearch side but I'm not familiar enough to know if this is a successful connection?

1

There are 1 answers

0
Pumpkin On

You may ping the server if you have initiated it by its java client.

You may try writing ( indexing ) something to it and check it out via its visualizer.

IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
        .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", new Date())
                        .field("message", "trying out Elasticsearch")
                    .endObject()
                  )
        .execute()
        .actionGet();

or you may try reading ( get operation ) something from it via java client..

GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .execute()
        .actionGet();