Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Spring Data OpenSearch Java Client Spring Boot Example Project

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.

Pre-requisites

Using Docker CLI

  1. 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
  1. Build and run the project using Gradle:
./gradlew :spring-data-opensearch-examples:spring-boot-java-client-gradle:bootRun
  1. 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'

Using Spring Boot Testcontainers integration

  1. Build and run the project using Gradle:
./gradlew :spring-data-opensearch-examples:spring-boot-java-client-gradle:bootTestRun
  1. 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'

Building as Native Image

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