-
Notifications
You must be signed in to change notification settings - Fork 41
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Latest is 2.14.0, any reason why it's 2.11? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have a bug on upgrading? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not really, but command line change, so "defaults" won't work anymore |
||
``` | ||
|
||
2. Build and run the project using [Gradle](https://gradle.org/): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Spring Data OpenSearch Java Client Spring Boot Example Project | ||
=== | ||
|
||
This sample project demonstrates the usage of the [Spring Data OpenSearch](https://github.com/opensearch-project/spring-data-opensearch/) in the typical Spring Boot web application using [opensearch-java](https://github.com/opensearch-project/opensearch-java) client. The application assumes that there is an [OpenSearch](https://opensearch.org) service up and running on the local machine, available at `https://localhost:9200` (protected by basic authentication with default credentials). | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
``` | ||
|
||
2. Build and run the project using [Gradle](https://gradle.org/): | ||
|
||
```shell | ||
./gradlew :spring-data-opensearch-examples:spring-boot-java-client-gradle:bootRun | ||
``` | ||
|
||
3. Exercise the REST endpoint available at: `http://localhost:8080/marketplace` | ||
|
||
- Fetch all products: `curl 'http://localhost:8080/marketplace/search'` | ||
- Search products by name: `curl 'http://localhost:8080/marketplace/search?name=pillow'` | ||
- Search products by name and price greater than: `curl 'http://localhost:8080/marketplace/search?name=pillow&price=35.0'` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
plugins { | ||
alias(springLibs.plugins.spring.boot) | ||
alias(pluginLibs.plugins.spotless) | ||
alias(pluginLibs.plugins.editorconfig) | ||
id("java-conventions") | ||
} | ||
|
||
buildscript { | ||
dependencies { | ||
classpath(pluginLibs.editorconfig) | ||
classpath(pluginLibs.spotless) | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":spring-data-opensearch")) { | ||
exclude("org.opensearch.client", "opensearch-rest-high-level-client") | ||
} | ||
api(project(":spring-data-opensearch-starter")) { | ||
exclude("org.opensearch.client", "opensearch-rest-high-level-client") | ||
} | ||
implementation(springLibs.boot.web) | ||
implementation(jacksonLibs.core) | ||
implementation(jacksonLibs.databind) | ||
implementation(opensearchLibs.client) | ||
implementation(opensearchLibs.java.client) | ||
testImplementation(springLibs.test) | ||
testImplementation(springLibs.boot.test) | ||
testImplementation(springLibs.boot.test.autoconfigure) | ||
testImplementation(opensearchLibs.testcontainers) | ||
testImplementation(project(":spring-data-opensearch-test-autoconfigure")) { | ||
exclude("org.opensearch.client", "opensearch-rest-high-level-client") | ||
} | ||
|
||
constraints { | ||
implementation("ch.qos.logback:logback-classic") { | ||
version { | ||
require("1.4.12") | ||
} | ||
because("Fixes CVE-2023-6378") | ||
} | ||
} | ||
} | ||
|
||
description = "Spring Data OpenSearch Spring Boot Example Project" | ||
|
||
spotless { | ||
java { | ||
target("src/main/java/**/*.java", "src/test/java/org/opensearch/**/*.java") | ||
|
||
trimTrailingWhitespace() | ||
indentWithSpaces() | ||
endWithNewline() | ||
|
||
removeUnusedImports() | ||
importOrder() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.data.example; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration; | ||
|
||
@SpringBootApplication(exclude = ElasticsearchDataAutoConfiguration.class) | ||
public class MarketplaceApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(MarketplaceConfiguration.class, args); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.data.example; | ||
|
||
import java.security.KeyManagementException; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; | ||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; | ||
import org.apache.http.ssl.SSLContextBuilder; | ||
import org.opensearch.client.RestClientBuilder; | ||
import org.opensearch.data.example.repository.MarketplaceRepository; | ||
import org.opensearch.spring.boot.autoconfigure.RestClientBuilderCustomizer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; | ||
|
||
@Configuration | ||
@EnableElasticsearchRepositories(basePackageClasses = MarketplaceRepository.class) | ||
@ComponentScan(basePackageClasses = MarketplaceConfiguration.class) | ||
public class MarketplaceConfiguration { | ||
/** | ||
* Allow to connect to the OpenSearch instance which uses self-signed certificates | ||
*/ | ||
@Bean | ||
RestClientBuilderCustomizer customizer() { | ||
return new RestClientBuilderCustomizer() { | ||
@Override | ||
public void customize(HttpAsyncClientBuilder builder) { | ||
try { | ||
builder.setSSLContext(new SSLContextBuilder() | ||
.loadTrustMaterial(null, new TrustSelfSignedStrategy()) | ||
.build()); | ||
} catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) { | ||
throw new RuntimeException("Failed to initialize SSL Context instance", ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void customize(RestClientBuilder builder) { | ||
// No additional customizations needed | ||
} | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
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.