# Initializing a RestHighLevelClient for ElasticSearch

**URL:** <https://discuss.elastic.co/t/initializing-a-resthighlevelclient-for-elasticsearch/135957>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 3:37pm UTC](https://discuss.elastic.co/t/initializing-a-resthighlevelclient-for-elasticsearch/135957 "2018-06-14T15:37:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anna10](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@anna10](https://discuss.elastic.co/u/anna10)\
**Post date:** [June 14, 2018, 3:37pm UTC](https://discuss.elastic.co/t/initializing-a-resthighlevelclient-for-elasticsearch/135957/1 "2018-06-14T15:37:49Z")

</div>

In the documentation [here](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.3/java-rest-high-getting-started-initialization.html), they initialize an instance of the client with the following code:

```auto
RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(
                new HttpHost("localhost", 9200, "http"),
                new HttpHost("localhost", 9201, "http")));

```

I've configured my ElasticSearch instance on the AWS Console following [these instructions](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html). On the summary page for my newly created instance, there is no port number with the domain.

So my question is, given how I've configured my instance how can I set up and make requests using a RestHighLevelClient if I'm not running the instance locally? I've tried

```auto
 RestHighLevelClient myRestHighLevelClient = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(ELASTIC_ENDPOINT_DEV)
                )
        );

        GetRequest getRequest = new GetRequest("myIndex", "myType","myID");
        myRestHighLevelClient.get(getRequest);

```

But I am returned with a java.net.ConnectionException: Connection Refused. Please help!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 14, 2018, 4:42pm UTC](https://discuss.elastic.co/t/initializing-a-resthighlevelclient-for-elasticsearch/135957/2 "2018-06-14T16:42:14Z")

</div>

You should ask AWS support for this.

Did you look at [https://www.elastic.co/cloud](https://www.elastic.co/cloud) and [https://aws.amazon.com/marketplace/pp/B01N6YCISK](https://aws.amazon.com/marketplace/pp/B01N6YCISK) ?

Cloud by elastic is the only way to have access to X-Pack. Think about what is there yet like Security, Monitoring, Reporting and what is coming like Canvas, SQL... And 6.3.0 is yet available there!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 12, 2018, 4:42pm UTC](https://discuss.elastic.co/t/initializing-a-resthighlevelclient-for-elasticsearch/135957/3 "2018-07-12T16:42:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
