rbrower3 / openshift-elasticsearch-cartridge

Apache License 2.0
31 stars 17 forks source link

Transport client in/from Java howto #13

Open gkfirst8 opened 9 years ago

gkfirst8 commented 9 years ago

How can I use this gear from Java?

In a local setup I use:

TransportClient createTransportClient(String clusterName, String esHost, int port) {
    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
    settingsBuilder.put(PARAM_CLUSTER_NAME, clusterName);
    LOG.info("Using host {}:{}", esHost, port);
    return new TransportClient(settingsBuilder.build()) //
            .addTransportAddress(new InetSocketTransportAddress(esHost, port));
}

But then I need to contact the normal port 9300. And haproxy used in OpenShift does not relay this port. It is only accessible using the 'rhc port-forward'.

The only other option I ran into is Jest (described here: https://www.found.no/foundation/java-clients-for-elasticsearch/) which also explained the challenges for both primary apis. Jest uses the REST-API and hence can easily contact remote Elasticsearch-clusters. But the framework used here (Spring Data) does not (yet) support Jest as the connection-layer.

Help would be much appreciated.

gkfirst8 commented 9 years ago

The transport-client seems to be accessible via a 10-range address which is available on the elasticsearch gear under the environment variable $OPENSHIFT_ELASTICSEARCH_CLUSTER. Hence we can just use this in the above TransportClient.

remyagss commented 8 years ago

Hi. I couldnot connect to OpenShift Es server from my java app. can you please tell me the connection paramaters like cluster.name,host,port. Please reply

gkfirst8 commented 8 years ago

I think the change of OpenShift to version 3.0 dropped the implicit support for this approach. I'm sorry, it is no longer usable.

unsalted commented 8 years ago

Based on what i'm reading here am I mistaken in assuming this deployment is out of date and no longer works?