This sample project demonstrates the usage of the Spring Data OpenSearch in the typical Spring Boot web application. The application assumes that there is an OpenSearch service up and running on the local machine.
This example uses the opensearch-java client.
- Docker
- Java 17
- Start OpenSearch using
docker run -p 9200:9200 -e "discovery.type=single-node" -e OPENSEARCH_INITIAL_ADMIN_PASSWORD=<strong-password> opensearchproject/opensearch:3.1.0- Build and run the project using Gradle:
./gradlew :spring-data-opensearch-examples:spring-boot-java-client-gradle:bootRun-
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'
- Fetch all products:
- Build and run the project using Gradle:
./gradlew :spring-data-opensearch-examples:spring-boot-java-client-gradle:bootTestRun-
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'
- Fetch all products:
This example can be built as a GraalVM native image for fast startup and low memory usage. You can run build and run the native image using Gradle:
./gradlew :spring-data-opensearch-examples:spring-boot-java-client-gradle:nativeRun