How to connect to AWS Elasticsearch?

As John Russell said above, you need to use a REST client to communicate with your AWS Elastic cluster.

Elastic recently released the first RC version of its own Java REST client, so this is an option now as well.

Client Docs: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html

Maven Repo: http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.elasticsearch.client%22%20AND%20a%3A%22rest%22


Since the Elasticsearch Java SDK version 5.6 there is a REST Client available. This allows you to connect to Elasticsearch Service on AWS.

Currently Elasticsearch Service allows installations up to version 5.5, but you can use the 5.6 Java SDK against a 5.5 cluster with minor limitations.

Note: When initializing the RestClient you should use the port 80 or 443 respectively instead of the 9200. E.g.

RestClient restClient = RestClient.builder(
    new HttpHost("search-test-elasti-xxxx-xxxxx.us-east-1.es.amazonaws.com", 80, "http")).build();
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClient); 
// [...]

How to get the AWS ES URL

Go to the Elasticsearch Domain console and get the Endpoint in the Overview tab.

Port to use is 443.

enter image description here

Make sure the access control has been configured.

  • Options for granting or denying access to Amazon ES endpoints

enter image description here


FYI

Create an Elasticsearch Index

curl -v -XPUT "${ES_ENDPOINT}/article/" -H 'Content-Type: application/json' -d '{
    "settings" : {
        "index" : {
            "number_of_shards" : 1,
            "number_of_replicas" : 0
        }
    }
}'

The native transport protocol is not support using AWS Managed ElasticSearch and is only available over the REST endpoint. Consider switching your client to consume the REST endpoint, such as https://github.com/searchbox-io/Jest.

Source: https://forums.aws.amazon.com/thread.jspa?messageID=681938