# Cannot use RestHighLevelClient.performRequest() because of protected access

**URL:** https://discuss.elastic.co/t/cannot-use-resthighlevelclient-performrequest-because-of-protected-access/157615
**Category:** Elasticsearch
**Created:** [November 20, 2018, 10:50pm UTC](https://discuss.elastic.co/t/cannot-use-resthighlevelclient-performrequest-because-of-protected-access/157615 "2018-11-20T22:50:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mikeg008](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mikeg008](https://discuss.elastic.co/u/mikeg008)
#### Post date: [November 20, 2018, 10:50pm UTC](https://discuss.elastic.co/t/cannot-use-resthighlevelclient-performrequest-because-of-protected-access/157615/1 "2018-11-20T22:50:23Z")

</div>

I'm currently in the process of switching our system from using the `TransportClient`, to the RestHighLevel client. We are using the Rest Client v5.6 and following these instructions for migrating: [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/\_changing\_the\_application\_8217\_s\_code.html#java-rest-high-level-migration-manage-indices](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/_changing_the_application_8217_s_code.html#java-rest-high-level-migration-manage-indices)

I copied the code from the migration guide into my configuration object, but there's one method that I can't get to from my class.  
My problem is, the following line (that is copied from the migration guide) is showing an error in IntelliJ:  
`Response response = restClient.performRequest("PUT", "my-index", emptyMap(), entity);`

The error I see is:  
`'performRequest()' has protected access in 'org.elasticsearch.client.RestHighLevelClient'`  
I have confirmed that RestHighLevelClient.performRequest() does have protected access.

Am I misunderstanding how to use the example code?

Here is my config file with the problem code:

```
package com.sample.web.config;

import org.apache.http.*;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NStringEntity;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

import static java.util.Collections.emptyMap;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;

@Configuration
public class ElasticSearchConfiguration {
@Value("${elasticsearch.cluster.name:elasticsearch}")
private String esClusterName;
@Value("${elasticsearch.host:localhost}")
private String esHost;
@Value("${elasticsearch.rest.port}")
private Integer esPort;

@Bean
public RestHighLevelClient createESRestHighLevelClient() throws IOException{
    RestClient lowLevelRestClient = getLowLevelRestClient();
    RestHighLevelClient restClient = new RestHighLevelClient(lowLevelRestClient);

    Settings indexSettings = Settings.builder()
            .put("cluster.name", esClusterName)
            .build();

    String payload = XContentFactory.jsonBuilder()
            .startObject()
            .startObject("settings")
            .value(indexSettings)
            .endObject()
            .startObject("mappings")
            .startObject("doc")
            .startObject("properties")
            .startObject("time")
            .field("type", "date")
            .endObject()
            .endObject()
            .endObject()
            .endObject()
            .endObject().string();

    HttpEntity entity = new NStringEntity(payload, ContentType.APPLICATION_JSON);

    Response response = restClient.performRequest("PUT", "my-index", emptyMap(), entity);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {

    }
    return restClient;
}

private RestClient getLowLevelRestClient() {
    return RestClient.builder(
            new HttpHost(esHost, esPort, "http")).build();
}

}
```

---

<div class="post-metadata">

### Author: ![mikeg008](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mikeg008](https://discuss.elastic.co/u/mikeg008)
#### Post date: [November 21, 2018, 2:46pm UTC](https://discuss.elastic.co/t/cannot-use-resthighlevelclient-performrequest-because-of-protected-access/157615/2 "2018-11-21T14:46:58Z")

</div>

Solved. The `restClient` object in the migration guide is apparently a Low Level Rest Client, not a High Level Rest Client. Switching it fixed the issue.

---

<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: [December 19, 2018, 2:47pm UTC](https://discuss.elastic.co/t/cannot-use-resthighlevelclient-performrequest-because-of-protected-access/157615/3 "2018-12-19T14:47:07Z")

</div>

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