# Migration from HLRC to Java API

**URL:** <https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 23, 2022, 3:24pm UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479 "2022-03-23T15:24:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [March 23, 2022, 3:24pm UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/1 "2022-03-23T15:24:29Z")

</div>

In this page talking about migration  
[https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/migrate-hlrc.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/migrate-hlrc.html)  
I found this

` keep the existing code as-is and use the new Java API Client for new features in your application, then later migrate the existing code,`

How can I do that since **HLRC support was totally removed in ES8+**?  
Should I use jars files **from the 7.17.1 for HLRC** and jar files **from ES8+ for Java API**?  
My app should have **both jar files from both versions** at the same time ?  
Are packages totally separated so that everything can cohabitate smoothly ?

Could you provide some more practical explanations on this point ?

---

<div class="post-metadata">

**Author:** ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)\
**Post date:** [March 23, 2022, 4:46pm UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/2 "2022-03-23T16:46:30Z")

</div>

Thanks for the report, indeed this doc needs to be clarified and expanded.

I understand your server is in version 8.x.

You can use HLRC version 7.17.1 alongside the Java API client 8.x, with both using the same `RestClient` for http communication.

An important point though is that you have to enable the "compatibility mode" on HRLC: it will then send additional HTTP headers that inform ES8 to use a 7.x compatible mode to parse requests and send responses:

```java
RestHighLevelClient = new RestHighLevelClientBuilder(restClient)
   .setApiCompatibilityMode(true)
   .build();

```

---

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [March 24, 2022, 8:19am UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/3 "2022-03-24T08:19:35Z")

</div>

Thank you Sylvain for this compatibility information

---

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [April 1, 2022, 7:04am UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/4 "2022-04-01T07:04:23Z")

</div>

Digging further, I get a discrepancy:

My **cluster is 8.0.1**

I have an existing **HLRC client**

If I use a **HLRC client with 7.17.1 jars**

1. I can compile it
2. I could not find the **.setApiCompatibilityMode(true)** anywhere
3. Trying to index , I get : **Unable to parse response body for Response{requestLine=POST /\_bulk?timeout=1m HTTP/1.1, host=http://localhost:9200, response=HTTP/1.1 200 OK}**

If I use a client **with 8.1.0 jars**

1. The Maven dependencies provides me **2 elastic jars**
2. There is **no way I can compile my HLRC client** since eveything vanished

I do not get **where the compatibility is** and what the "smooth transition" could be 🫠  
Can you provide some more explanations ?

---

<div class="post-metadata">

**Author:** ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)\
**Post date:** [April 1, 2022, 3:04pm UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/5 "2022-04-01T15:04:09Z")

</div>

The [docs have been clarified](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/migrate-hlrc.html) with an example that includes `setApiCompatibilityMode`.

You can use the Java API client version `8.x` alongside HLRC version `7.17` (with compatibility mode enabled) with a `8.x` Elasticsearch cluster.

Note: there are some HLRC versions 8.0.0-alpha on Maven Central, these should be ignored. However we keep releasing patch versions with bug fixes in the 7.17 branch. Version 7.17.2 was released a few days ago.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![charvi23](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charvi23/32/103607_2.png) [@charvi23](https://discuss.elastic.co/u/charvi23)\
**Post date:** [April 8, 2022, 7:10am UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/7 "2022-04-08T07:10:58Z")

</div>

What about other versions of HLRC? Can Elasticsearch 8 cluster be made compatible with those? I am facing issue while writing the index when using HLRC 7.15.

---

<div class="post-metadata">

**Author:** ![charvi23](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charvi23/32/103607_2.png) [@charvi23](https://discuss.elastic.co/u/charvi23)\
**Post date:** [April 11, 2022, 11:59am UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/8 "2022-04-11T11:59:06Z")

</div>

I was able to make changes and update it to versions to following:  
HighlevelRestClient : 7.17.2  
Elasticsearch cluster 8.0.1

I have set the compatibility to true. I get the following error now:

```auto
java.lang.NoSuchMethodError: org.elasticsearch.client.RequestOptions$Builder.getHeaders()Ljava/util/List;
	at org.elasticsearch.client.RestHighLevelClient.addCompatibilityFor(RestHighLevelClient.java:2632)
	at org.elasticsearch.client.RestHighLevelClient.modifyRequestForCompatibility(RestHighLevelClient.java:2673)
	at org.elasticsearch.client.RestHighLevelClient.performClientRequest(RestHighLevelClient.java:2687)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:2171)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:2137)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:2105)
	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1367)
	at org.elasticsearch.client.KotlinExtensionsKt.search(KotlinExtensions.kt:212)

```

Do I need to headers separately? I changed my connector code to following using HLRC.

```nohighlight
            HttpHost(elasticSearchProps.host, elasticSearchProps.port)
        ).setRequestConfigCallback { requestConfigBuilder ->
            requestConfigBuilder
                .setConnectTimeout(5000)
                .setSocketTimeout(300000)
        }.build()

        val hlrc = RestHighLevelClientBuilder(httpClient)
            .setApiCompatibilityMode(true)
            .build()

        return hlrc
    }

```

I get this error once I try to use this hlrc created to search a index, which was earlier working fine with 7.15.

---

<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:** [May 9, 2022, 11:59am UTC](https://discuss.elastic.co/t/migration-from-hlrc-to-java-api/300479/9 "2022-05-09T11:59:45Z")

</div>

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