How do I configure Elastic search endpoint in java code?

(Vinayak Fulari) #1

While creating lambda function we have sample blueprint for node js, python but not for java.
I want to connect to my domain (which is created in AWS Elastic search service) by using my java program.
Here I have endpoint for my domain. So how do I configure this in my java code. ?

Kindly respond it as early as possible.

Thanking you in anticipation....

My code is as below.

public class StreamTransferService{
public static void main(String[] args) {
Client client = null;
Settings set= Settings.settingsBuilder().put("", "xxxxxx")
.put("number_of_shards", 1)
.put("number_of_replicas", 1)

    client = TransportClient.builder().settings(set).build();                 
    try {
        client = TransportClient.builder().build()                   
        		.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(""), 80));
    } catch (UnknownHostException e) {        	
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    String indexName="all_products";
	CreateIndexResponse response = client.admin().indices().create(new CreateIndexRequest(indexName)).actionGet();
	if (!response.isAcknowledged()) {
		throw new RuntimeException("cannot create index " + indexName);


(Daniel Mitterdorfer) #2

Disclaimer: I work for Elastic, the company behind Elasticsearch and also Elastic Cloud

Hi @Vinayak_Fulari,

As stated in Amazon's Elasticsearch service documentation you're out of luck:

The service supports HTTP on port 80, but does not support TCP transport.

If you are looking for an alternative that supports this, you can give Elastic Cloud a go.


(system) #3