# Java connection help to OpenSearch

**URL:** <https://forum.opensearch.org/t/java-connection-help-to-opensearch/14860>\
**Category:** OpenSearch Client Libraries\
**Tags:** opensearch-java\
**Created:** [June 28, 2023, 9:06am UTC](https://forum.opensearch.org/t/java-connection-help-to-opensearch/14860 "2023-06-28T09:06:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![localforecast391](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@localforecast391](https://forum.opensearch.org/u/localforecast391)\
**Post date:** [June 28, 2023, 9:06am UTC](https://forum.opensearch.org/t/java-connection-help-to-opensearch/14860/1 "2023-06-28T09:06:36Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
Java 8  
Opensearch 2.4.0

**Describe the issue** :  
I’m unable to connect to my OpenSearch cluster due to versions compatibilities. I think this is because OpenSearch 2.0 does not have support for Java 8 but what is the alternative.

How do I connect my java 8 application to OpenSearch

**Configuration** :  
public OpenSearchClient getClient() {  
SdkHttpClient httpClient = ApacheHttpClient.builder().build();  
return new OpenSearchClient(  
new AwsSdk2Transport(  
httpClient,  
host,  
“es”,  
Region.of(region),  
AwsSdk2TransportOptions.builder().build()  
)  
);  
}

This does not compile

---

<div class="post-metadata">

**Author:** ![wbeckler](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@wbeckler](https://forum.opensearch.org/u/wbeckler)\
**Post date:** [June 28, 2023, 8:08pm UTC](https://forum.opensearch.org/t/java-connection-help-to-opensearch/14860/2 "2023-06-28T20:08:53Z")

</div>

Is there any way you can run this in a higher version of java?

Here’s the status on java 8 support in opensearch-java:

> <https://github.com/opensearch-project/opensearch-java/issues/156>
>
> \## What kind of business use case are you trying to solve? What are your require…ments?
> 
> Many users still need Java 8 for their clients for maximum Java compatibility.
> 
> \*\*What is the problem? What is preventing you from meeting the requirements?\*\*
> 
> With the introduction of OpenSearch 2.0.0, the OpenSearch 2.0.0 build has updated to Java 11. This also includes the \`opensearch-rest-client\` and \`opensearch-rest-high-level-client\` clients.
> 
> Users of clients who wish to update their client version must now update to Java 11.
> 
> Additionally, the opensearch-java client relies on the \`opensearch-rest-client\`. Per opensearch-project/opensearch-clients#17, this is the client which is meant to have the most compatibility. 
> 
> Here is an example of updating Data Prepper (which currently supports Java 8):
> 
> \`\`\`
> \> No matching variant of org.opensearch.client:opensearch-rest-high-level-client:2.0.0-rc1 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally but:
> - Variant 'apiElements' capability org.opensearch.client:opensearch-rest-high-level-client:2.0.0-rc1 declares a library, packaged as a jar, and its dependencies declared externally:
> - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
> - Variant 'runtimeElements' capability org.opensearch.client:opensearch-rest-high-level-client:2.0.0-rc1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
> - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
> \`\`\`
> 
> \*\*What are you proposing? What do you suggest we do to solve the problem or improve the existing situation?\*\*
> 
> I propose that the OpenSearch Core's \`opensearch-rest-client\` and \`opensearch-rest-high-level-client\` projects be made to use Java 8. The Gradle build can setup the \`sourceCompatibility\` and \`targetCompatibility\` to ensure that it uses only Java 8 language features.
> 
> An alternative solution would be to remove the dependency that \`opensearch-java\` has on \`opensearch-rest-client\`.
> 
> \*\*What are your assumptions or prerequisites?\*\*
> 
> None.
> 
> \*\*What are remaining open questions?\*\*
> 
> Can Gradle toolchains or another mechanism help ensure that the client projects do not use any Java 11 APIs?

Feel free to participate or comment in that issue.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)\
**Post date:** [August 27, 2023, 8:09pm UTC](https://forum.opensearch.org/t/java-connection-help-to-opensearch/14860/3 "2023-08-27T20:09:15Z")

</div>

Closed on August 27, 2023, 8:09pm UTC

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