Git Product home page Git Product logo

kasramp / spring-data-elasticsearch-example Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 31.0 53 KB

An example of Spring Data Elasticsearch with Spring Boot 3 and Elasticsearch version 8

Home Page: https://geekyhacker.com/getting-started-with-spring-data-elasticsearch/

License: GNU General Public License v3.0

Java 100.00%
spring spring-boot spring-data spring-data-elasticsearch springframework docker-compose testcontainers junit5 springboot3 springboot3-x

spring-data-elasticsearch-example's Introduction

Spring Data Elasticsearch Example with Spring Boot 3 and ElasticSearch 8

Introduction

This example demonstrates how to use Spring Data Elasticsearch to do simple CRUD operations.

You can find the tutorial about this example at this link: Getting started with Spring Data Elasticsearch

For this example, we created a Book controller that allows doing the following operations with Elasticsearch:

  • Get the list of all books
  • Create a book
  • Update a book by Id
  • Delete a book by Id
  • Search for a book by ISBN
  • Fuzzy search for books by author and title

How to run

Spring Boot 3.1

Since this project uses Spring Boot 3.1, all you need to do is to run the application:

$ ./mvnw spring-boot:run

Spring Boot automatically detects the docker-compose file and starts the Elasticsearch container.

Spring Boot 3.0 and prior

The older version of this project uses Spring Boot 3.0 which does not have Spring Boot Docker Compose integration.

To run an older version of the application, the first thing to do is to start Elasticsearch. For that, you can use the docker-compose file in this project and run it like this:

$ docker-compose -f docker-compose up -d

It brings Elasticsearch up on a single node cluster with the cluster name elasticsearch.

Then you can run the application like below:

$ ./mvnw spring-boot:run

If your Elasticsearch URI is not localhost is different simply override the following environment variable:

  • ES_URI

Once everything is up and running open the browser and go to http://localhost:8080. You should see Swagger to interact with.

Run Testcontainers tests

The integration tests are written relying on Testcontainers to spin up Elasticsearch on the spot and run tests against it. To know more about container testing read this tutorial: Integration test with Testcontainers in Java

To run the integration test (using Testcontainers) just run the below command:

$ mvn clean verify

Make sure you have your docker running.

spring-data-elasticsearch-example's People

Contributors

jarjanazy avatar kasramp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spring-data-elasticsearch-example's Issues

Missing BookDto class

Nice sample.

I want to ask where is BookDto class located?
Am I Missing BookDto class?

Thanks

Add Spring Boot Docker Compose integration

Spring Boot 3.1 supports Docker Compose. Upgrade the dependencies and add the integration, so that prior to starting the application, no need to run docker-compose up

Problem with Spring boot 2.7.8

Hello,

I tried using your example of test container usage for elastic search, in my project which uses SB 2.7.8.

I ran into a problem when executing spring boot test (integration test) getting "Connection closed exception".
I also get the same exception when upgrading your project to use spring boot starter parent 2.7.8, and then doing necessary changes due to different versions.

Do you have idea how to solve the problem?

Overall there seem to be issues on how to setup spring boot test with testcontainers for ES and SpringBoot 2.7.8.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.