How to utilize Java NodeClient for a cluster running on AWS/EC2

(austin lee) #1

So I have a java application that is able to connect to my ES cluster using the Transport client with no problems. Now I'm trying to gauge whether to use the transport or node client.

However, I'm not too sure how to connect to an ES cluster on EC2. I originally blindly used the examples without realizing those were for multi-cast discovery. I guess in terms of deployment/settings my questions...

a) Does my java application have to allow for incoming traffic on port 9200 and 9300 or can it just be 9300 or do I even need it.
b) What are the settings I need to pass into my node client? I have http.enabled = false,, discovery.type=ec2,
c) Does my java application requires any additional jars such as the aws ec2 jar or the elasticsearch-cloud-aws jar?
d) Am I missing anything else?

(Srinath C) #2

You would need to allow incoming traffic from port 9300 but make sure you allow that only from ES instances' security group. We use NodeClient and initialize it with the following settings:

                .put("", clusterName)
                .put("http.enabled", false)
                .put("", false)
                .put("client.transport.sniff", false)
                .put("client.transport.ping_timeout", pingTimeout)

Multicast is disabled but we discover the instances via other means and add it to the client instance. We only depend on elasticsearch jars only since we dont use ec2 discovery.
Naming the node client will be a good thing to do.

(austin lee) #3

So I figured it out by trial and error. It is actually in the doucmentation of the plugin but it just didn't seem obvious to me those same settings you put in the yml file can be added to the node client. You do need to include the plugin jar to your java application as well.

I do use ec2 discovery. Here are settings.

ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
.put("", false)
.put("discovery.type", "ec2")
.put("discovery.ec2.tag.myTag", "Any ec2 instances you've tagged")
.put("", com.amazonaws.regions.Regions.getCurrentRegion())
.put("discovery.ec2.groups", "a list of security groups here");

So you can either use the tag approach or security groups or both. After that I then create my node client specifying the cluster name and setting data to false and client to true.

node = nodeBuilder().clusterName("myclustername").data(false).

(system) #4