Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opensearch-java client support #227

Merged
merged 1 commit into from
May 21, 2024
Merged

Conversation

reta
Copy link
Collaborator

@reta reta commented Jan 19, 2024

Description

Add opensearch-java client support

Issues Resolved

Closes #19

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@reta reta force-pushed the issue-19 branch 4 times, most recently from 0471a42 to 87549ee Compare January 25, 2024 16:01
@reta reta force-pushed the issue-19 branch 3 times, most recently from ce0fba3 to 643180b Compare February 23, 2024 14:33
@reta reta force-pushed the issue-19 branch 2 times, most recently from b9ca04f to 79d00b8 Compare April 4, 2024 17:04
@reta reta force-pushed the issue-19 branch 5 times, most recently from ead77f9 to 873b049 Compare April 16, 2024 16:10
@calvinch
Copy link

Any idea when this PR will be merged?

@reta
Copy link
Collaborator Author

reta commented Apr 25, 2024

Any idea when this PR will be merged?

@calvinch I will resume the work next week, needs new client favour + tests

@reta reta force-pushed the issue-19 branch 4 times, most recently from 7cb4ba3 to 544699f Compare May 3, 2024 15:08
@reta reta force-pushed the issue-19 branch 5 times, most recently from 9bcb6f1 to e5dfdcf Compare May 7, 2024 20:54
@reta reta force-pushed the issue-19 branch 5 times, most recently from 94eece3 to 001102c Compare May 8, 2024 19:06
@reta reta marked this pull request as ready for review May 8, 2024 19:06
@reta reta requested review from dblock and dlvenable as code owners May 8, 2024 19:06
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
@reta
Copy link
Collaborator Author

reta commented May 21, 2024

@dblock I am wondering if you could help me getting this one in, 🙇

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a very cursory look at this and it LGTM, YOLO.

@@ -33,13 +33,18 @@ The Spring Data OpenSearch follows the release model of the Spring Data Elastics

### OpenSearch 2.x / 1.x client libraries

At the moment, Spring Data OpenSearch provides the possibility to use the `RestHighLevelCLient` to connect to OpenSearch clusters.

At the moment, Spring Data OpenSearch provides the possibility to use either `RestHighLevelCLient` or [OpenSearchClient](https://github.com/opensearch-project/opensearch-java) to connect to OpenSearch clusters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove "At the moment, ", doesn't add any value, it's just documentation.

@@ -6,7 +6,7 @@ This sample project demonstrates the usage of the [Spring Data OpenSearch](https
1. The easiest way to get [OpenSearch](https://opensearch.org) service up and running is by using [Docker](https://www.docker.com/):

```shell
docker run -p 9200:9200 -e "discovery.type=single-node" opensearchproject/opensearch:2.4.0
docker run -p 9200:9200 -e "discovery.type=single-node" opensearchproject/opensearch:2.11.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest is 2.14.0, any reason why it's 2.11?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the last version before requiring the mandatory password, the command line changed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a bug on upgrading?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a bug on upgrading?

Not really, but command line change, so "defaults" won't work anymore

1. The easiest way to get [OpenSearch](https://opensearch.org) service up and running is by using [Docker](https://www.docker.com/):

```shell
docker run -p 9200:9200 -e "discovery.type=single-node" opensearchproject/opensearch:2.11.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just use :latest?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would afraid to go with latest since we have changes that may prevent container from starting

@dblock dblock merged commit 3eea4a9 into opensearch-project:main May 21, 2024
12 checks passed
@Neuw84
Copy link

Neuw84 commented May 21, 2024

Will update the sample integration with SpringBoot that I have as soon as we have this on maven central:

https://github.com/aws-samples/opensearch-bootful

Thanks for this!

@reta reta mentioned this pull request May 21, 2024
5 tasks
@Neuw84
Copy link

Neuw84 commented Jul 15, 2024

Hi @reta,

One question, apart from the opensearch-bootful I am working on release another sample with knn index and for that I need this to work on opensearch-java client.

I have configured the starter as needed via the exclusion of the old client.

            <groupId>org.opensearch.client</groupId>
            <artifactId>spring-data-opensearch</artifactId>
            <version>1.5.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.opensearch.client</groupId>
                    <artifactId>opensearch-rest-high-level-client</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.opensearch.client</groupId>
            <artifactId>opensearch-java</artifactId>
            <version>2.11.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.3.1</version>
        </dependency>

but then, I don´t know how to configure the client for spring-data as AbstractOpenSearchConfiguration is expecting a RestHighLevelClient. My class using the old client was this one.

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.aws.samples.opensearch.repository")
@Slf4j
public class OpenSearchRestClientConfiguration extends AbstractOpenSearchConfiguration {

  @Value("${aws.os.endpoint}")
  private String endpoint = "";

  @Value("${aws.os.region}")
  private String region = "";

  @Value("${aws.os.username}")
  private String username = "";

  @Value("${aws.os.password}")
  private String password = "";



  @Override
  @Bean
  public RestHighLevelClient opensearchClient() {

    final ClientConfiguration clientConfiguration =
        ClientConfiguration.builder()
            .connectedTo(endpoint)
            .usingSsl()
            .withBasicAuth(username,password)
            .withConnectTimeout(Duration.ofSeconds(10))
            .withSocketTimeout(Duration.ofSeconds(5))
            .build();
    return RestClients.create(clientConfiguration).rest();
  }
}

Any hints?

Thanks!!

@reta
Copy link
Collaborator Author

reta commented Jul 15, 2024

but then, I don´t know how to configure the client for spring-data as AbstractOpenSearchConfiguration is expecting a RestHighLevelClient. My class using the old client was this one.

Hi @Neuw84 ,

You just need to replace AbstractOpenSearchConfiguration with org.opensearch.data.client.osc.OpenSearchConfiguration, for example:

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.aws.samples.opensearch.repository")
@Slf4j
public class OpenSearchClientConfiguration extends OpenSearchConfiguration {

        @Value("${aws.os.endpoint}")
        private String endpoint = "";
      
        @Value("${aws.os.region}")
        private String region = "";
      
        @Value("${aws.os.username}")
        private String username = "";
      
        @Value("${aws.os.password}")
        private String password = "";

       @NonNull
        @Override
        public ClientConfiguration clientConfiguration() {
            return  ClientConfiguration.builder()
                    .connectedTo(endpoint)
                    .usingSsl()
                    .withBasicAuth(username,password)
                    .withConnectTimeout(Duration.ofSeconds(10))
                    .withSocketTimeout(Duration.ofSeconds(5))
                    .build();
        }
}

@Neuw84
Copy link

Neuw84 commented Jul 15, 2024

Thanks for the super quick reply, got it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add opensearch-java client support
4 participants