Migration from HLRC to Java API

In this page talking about migration
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 ?

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:

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

Thank you Sylvain for this compatibility information

1 Like

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 :melting_face:
Can you provide some more explanations ?

The docs have been clarified 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.

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.

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:

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.

            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.

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