3

I've set up a starter account on Heroku with a Bonsai elasticsearch add-on. I'm trying to connect to it via a Java application, but can't seem to connect via either Transport Client or the NodeBuilder options that are explained on the elasticsearch documentation pages.

I can run the following CURL to post data:

curl -XPOST http://banyan-7086980.us-east-1.bonsai.io/med/test/hello3 -d '{"title":"Hello world2"}'

My current line of thought is this:

    Client client = new TransportClient()
            .addTransportAddress(new InetSocketTransportAddress("http://banyan-7086980.us-east-1.bonsai.io", 9300));

But this is not working. What am I missing?

Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76

2 Answers2

0

Most services that offer hosted Elasticsearch on Heroku does not support any other transport than HTTP. The canonical way of interfacing with Elasticsearch from Java is using either the Transport client or the Node client, both of which you've tried connecting to HTTP-endpoints.

The transport and node clients use a custom-built binary protocol which is not compatible with HTTP.

Additionally, this binary protocol by default does not support some core features you should expect in a production setup: authentication and encryption.

If your requirements include running on Heroku and using the official Java clients, have a look at Found Elasticsearch on Heroku, which provides support for the transport client using a custom transport module: https://github.com/foundit/elasticsearch-transport-module

Disclosure: I'm one of the developers at Found

Njal Karevoll
  • 661
  • 5
  • 6
-1

Bonsai is a hosted service for elasticsearch, and if you are using the heroku addon, there are internals of both ES and Heroku that are abstracted.

For instance, the URL that you are hitting is at port 80 (http), whereas you are attempting to connect to 9300 (which is the default Elasticsearch port). This tells me that there is a proxy layer in between that is hiding ports 9200 and 9300 from the outside world, for security reasons.

What to do?

You could try connecting your Java client to port 80.

Client client = new TransportClient() .addTransportAddress(new InetSocketTransportAddress("http://banyan-7086980.us-east-1.bonsai.io", 80)); 

If you are using Heroku to host your application, follow the instructions of the Bonsai addon, use the ENV variables to setup the connection.

If you just want to have a hosted instance, you can use alternatives such as qbox for found

I prefer using Elasticsearch on Openshift.

Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76
  • The Java transport client is not HTTP-based. [Found](https://www.found.no/) supports the transport client via a small plugin that adds support for SSL and authentication. More on that here: https://www.found.no/documentation/tutorials/using-java-transport/ (Full disclosure: I work for Found) – Alex Brasetvik May 22 '14 at 10:30
  • good information-thanks! i'm looking for the best way to host. i'm running an application/utility from heroku, and saw bonsai on there and was initially trying to set that up. i'll take a look at Found and OpenShift (I've used OpenShift in the past, but wasn't aware they had elasticsearch hosting) –  May 23 '14 at 15:01